Actualizar backend/modules/cobranza/processor.py

This commit is contained in:
2026-10-06 13:31:10 -05:00
parent 419c07fd00
commit da70bc461a

View File

@@ -582,19 +582,33 @@ class CobranzaProcessor:
if clave_mat in alumnos_tracking: if clave_mat in alumnos_tracking:
alumnos_tracking[clave_mat]["resta"] += (resta_ant + resta_cur) alumnos_tracking[clave_mat]["resta"] += (resta_ant + resta_cur)
alumnos_tracking[clave_mat]["cobrado"] += (cobrado_ant + cobrado_curso) alumnos_tracking[clave_mat]["cobrado"] += (cobrado_ant + cobrado_curso)
# Si la cuota del mes ya se pagó (está en facturas), registrar su
# N° Cuota y Fecha de Vencimiento aquí también (para que no se pierdan
# al pagar). Solo si el cronograma no las registró antes.
if agrupacion == "PROGRAMA":
_fvcT = self.parse_fecha(fila.get('fch_vencimiento_cuota'))
if _fvcT and (fecha_filtro <= _fvcT < fecha_filtro_siguiente):
if alumnos_tracking[clave_mat].get("fecha_final") is None:
alumnos_tracking[clave_mat]["fecha_final"] = _fvcT.strftime('%d/%m/%Y')
if alumnos_tracking[clave_mat].get("cuota_final") is None:
try:
alumnos_tracking[clave_mat]["cuota_final"] = int(fila.get('num_cuota', -1))
except Exception:
pass
for (mat, llave), track in alumnos_tracking.items(): for (mat, llave), track in alumnos_tracking.items():
saldo_alumno = (track["suma"] - track["resta"]) - track["cobrado"] # N° Cuota y Fecha de Vencimiento del mes SIEMPRE se registran, haya pagado
if round(saldo_alumno, 2) > 0: # o no (antes solo si saldo>0, por eso desaparecían al pagar). La fecha de
c = track["cuota_final"] # vencimiento del mes no depende de si el alumno ya canceló.
f = track["fecha_final"] c = track["cuota_final"]
f = track["fecha_final"]
if c is not None: if c is not None:
if llave not in frecuencias_cuota: frecuencias_cuota[llave] = {} if llave not in frecuencias_cuota: frecuencias_cuota[llave] = {}
frecuencias_cuota[llave][c] = frecuencias_cuota[llave].get(c, 0) + 1 frecuencias_cuota[llave][c] = frecuencias_cuota[llave].get(c, 0) + 1
if f is not None: if f is not None:
if llave not in frecuencias_fecha_venc: frecuencias_fecha_venc[llave] = {} if llave not in frecuencias_fecha_venc: frecuencias_fecha_venc[llave] = {}
frecuencias_fecha_venc[llave][f] = frecuencias_fecha_venc[llave].get(f, 0) + 1 frecuencias_fecha_venc[llave][f] = frecuencias_fecha_venc[llave].get(f, 0) + 1
# Saldo POR RETIRAR por grupo: suma el saldo de los alumnos marcados POR RETIRAR # Saldo POR RETIRAR por grupo: suma el saldo de los alumnos marcados POR RETIRAR
# (mats_retirar) usando el tracking por (matricula, llave). # (mats_retirar) usando el tracking por (matricula, llave).
@@ -837,6 +851,19 @@ class CobranzaProcessor:
datos_agrupados[mat_factura]["Cob_Ant"] += cobrado_ant datos_agrupados[mat_factura]["Cob_Ant"] += cobrado_ant
datos_agrupados[mat_factura]["Cob_Cur"] += cobrado_curso datos_agrupados[mat_factura]["Cob_Cur"] += cobrado_curso
# Si la cuota del MES ya se pagó (está en facturas y no en el cronograma),
# igual registrar su N° Cuota y Fecha de Vencimiento del mes (para que NO
# desaparezcan al pagar). Solo si aún no se tenían.
_fvc = self.parse_fecha(fila.get('fch_vencimiento_cuota'))
if _fvc and (fecha_filtro <= _fvc < fecha_filtro_siguiente):
if datos_agrupados[mat_factura].get("Fch_Venc_Mes", "-") in ("-", "", None):
datos_agrupados[mat_factura]["Fch_Venc_Mes"] = _fvc.strftime('%d/%m/%Y')
if datos_agrupados[mat_factura].get("Cuota_Mes", "-") in ("-", "", None):
try:
datos_agrupados[mat_factura]["Cuota_Mes"] = str(int(fila.get('num_cuota', -1)))
except Exception:
pass
datos_limpios = [] datos_limpios = []
for mat, totales in datos_agrupados.items(): for mat, totales in datos_agrupados.items():
cta_cob_ant = totales["Suma_Ant"] - totales["Resta_Ant"] cta_cob_ant = totales["Suma_Ant"] - totales["Resta_Ant"]
@@ -850,11 +877,10 @@ class CobranzaProcessor:
if round(total_cta, 2) <= 0 and round(total_cob, 2) <= 0: continue if round(total_cta, 2) <= 0 and round(total_cob, 2) <= 0: continue
# N° Cuota y Fecha de Vencimiento del mes SIEMPRE se muestran, haya pagado
# o no (antes se borraban cuando saldo<=0, por eso desaparecían al pagar).
cuota_final = totales["Cuota_Mes"] cuota_final = totales["Cuota_Mes"]
fecha_final = totales["Fch_Venc_Mes"] fecha_final = totales["Fch_Venc_Mes"]
if round(saldo, 2) <= 0:
cuota_final = "-"
fecha_final = "-"
datos_limpios.append({ datos_limpios.append({
'MATRICULA': mat, 'ALUMNO': totales["Alumno"], 'MATRICULA': mat, 'ALUMNO': totales["Alumno"],