From acf82f1f8f2c4e70a81cbe03fee56a6fdbd7d319 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 22 Sep 2026 11:03:27 -0500 Subject: [PATCH] Actualizar backend/modules/ventas/logic.py --- backend/modules/ventas/logic.py | 46 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/backend/modules/ventas/logic.py b/backend/modules/ventas/logic.py index 91f9194..749f6d0 100644 --- a/backend/modules/ventas/logic.py +++ b/backend/modules/ventas/logic.py @@ -105,12 +105,12 @@ class VentasLogic: filas.append(fila) return filas - def obtener_datos_brutos(self, ano, mes_numero): - datos = self.data_manager.ejecutar_consulta_ventas(str(ano), str(mes_numero)) + def obtener_datos_brutos(self, ano, mes_numero, excluir_ret=False): + datos = self.data_manager.ejecutar_consulta_ventas(str(ano), str(mes_numero), excluir_ret=excluir_ret) return datos or [] - def obtener_datos_brutos_filtrado(self, ano, mes_numero, sede="TODOS", programa="TODOS"): - datos = self.data_manager.ejecutar_consulta_ventas(str(ano), str(mes_numero), sede, programa) + def obtener_datos_brutos_filtrado(self, ano, mes_numero, sede="TODOS", programa="TODOS", excluir_ret=False): + datos = self.data_manager.ejecutar_consulta_ventas(str(ano), str(mes_numero), sede, programa, excluir_ret=excluir_ret) return datos or [] # ========================================================================= @@ -163,9 +163,9 @@ class VentasLogic: set_vip_actual.add(val) lista_vip_str.append(str(val)) except: pass + # Lista PURA de BASE_PENDIENTES (sin overrides). Venta Pendientes usa SOLO esto. set_lista_pendientes = set(set_vip_actual) - # Incluir matrículas con override de fecha (igual que ejecutar_consulta_ventas) # Incluir matrículas con override de fecha (igual que ejecutar_consulta_ventas) _fov_vip = getattr(self.data_manager, '_fecha_canc_overrides', None) or {} @@ -221,8 +221,8 @@ class VentasLogic: datos_raw = [dict(zip(columns, row)) for row in cursor.fetchall()] # DEDUP por num_matricula: el LEFT JOIN con RP_programa puede duplicar filas - # (una con fch_cancelacion y otra sin). Nos quedamos con UNA sola por matrícula, - # priorizando la que TENGA fecha de cancelación (verdad del pago). + # (una con fch_cancelacion y otra sin). Nos quedamos con UNA sola fila por + # matrícula, priorizando la que TENGA fecha de cancelación (verdad del pago). _dedup = {} for _d in datos_raw: _m = str(_d.get('num_matricula', '')).strip() @@ -232,9 +232,9 @@ class VentasLogic: if _prev is None: _dedup[_m] = _d elif _tiene_f and not bool(_prev.get('fch_cancelacion_cuota1')): - _dedup[_m] = _d + _dedup[_m] = _d # reemplazar por la que sí tiene fecha datos_raw = list(_dedup.values()) - + # 🔥 DESCARGA DEL CRONOGRAMA COMPLETO (SIN IMPORTAR EL MES) 🔥 lista_mats = list(set([str(d.get('num_matricula')).replace('.0','').strip() for d in datos_raw if d.get('num_matricula')])) cuotas_raw = [] @@ -299,17 +299,6 @@ class VentasLogic: continue estado = str(d.get('estado_matricula', '')).strip().upper() - # Permitir ANU/otros si tiene override de fecha; si no, solo ALU/PRE/RET - _rm = d.get('num_matricula') - _mk = "" - if _rm is not None: - _mk = str(_rm).strip() - if _mk.endswith('.0'): _mk = _mk[:-2] - _fov_chk = getattr(self.data_manager, '_fecha_canc_overrides', None) or {} - if estado not in ['ALU', 'PRE', 'RET'] and _mk not in _fov_chk: continue - # En VENTAS (excluir_ret): los RET NO aparecen aunque hayan pagado. - if excluir_ret and estado == "RET": - continue raw_mat = d.get('num_matricula') mat_id = "" @@ -320,6 +309,20 @@ class VentasLogic: mat_id = val_str try: matricula_int = int(float(val_str)) except: pass + + # Permitir ANU/otros si tiene override de fecha O si está en tu lista + # BASE_PENDIENTES; si no, solo ALU/PRE/RET + _rm = d.get('num_matricula') + _mk = "" + if _rm is not None: + _mk = str(_rm).strip() + if _mk.endswith('.0'): _mk = _mk[:-2] + _fov_chk = getattr(self.data_manager, '_fecha_canc_overrides', None) or {} + if estado not in ['ALU', 'PRE', 'RET'] and _mk not in _fov_chk \ + and matricula_int not in set_vip_actual: continue + # En VENTAS (excluir_ret): los RET NO aparecen aunque hayan pagado. + if excluir_ret and estado == "RET": + continue dni = str(d.get('dsc_documento', '')).strip() alumno_nombre = d.get('dsc_alumno', 'SIN NOMBRE') @@ -633,7 +636,8 @@ class VentasLogic: agregar_a_lista("Venta P.C") # VENTA PENDIENTES: SOLO de tu lista BASE_PENDIENTES y que pagaron su 1ª - # cuota EN EL MES/AÑO DEL FILTRO. Usa la FECHA REAL DEL SQL (sin override). + # cuota EN EL MES/AÑO DEL FILTRO. Usa la FECHA REAL DEL SQL (sin override), + # porque los overrides NO deben afectar Venta Pendientes. _pago_mes_real = False if fch_canc_real_sql and str(fch_canc_real_sql).strip() != "None": try: