Actualizar backend/modules/ventas/logic.py
This commit is contained in:
@@ -105,12 +105,12 @@ class VentasLogic:
|
|||||||
filas.append(fila)
|
filas.append(fila)
|
||||||
return filas
|
return filas
|
||||||
|
|
||||||
def obtener_datos_brutos(self, ano, 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))
|
datos = self.data_manager.ejecutar_consulta_ventas(str(ano), str(mes_numero), excluir_ret=excluir_ret)
|
||||||
return datos or []
|
return datos or []
|
||||||
|
|
||||||
def obtener_datos_brutos_filtrado(self, ano, mes_numero, sede="TODOS", programa="TODOS"):
|
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)
|
datos = self.data_manager.ejecutar_consulta_ventas(str(ano), str(mes_numero), sede, programa, excluir_ret=excluir_ret)
|
||||||
return datos or []
|
return datos or []
|
||||||
|
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
@@ -163,9 +163,9 @@ class VentasLogic:
|
|||||||
set_vip_actual.add(val)
|
set_vip_actual.add(val)
|
||||||
lista_vip_str.append(str(val))
|
lista_vip_str.append(str(val))
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
# Lista PURA de BASE_PENDIENTES (sin overrides). Venta Pendientes usa SOLO esto.
|
# Lista PURA de BASE_PENDIENTES (sin overrides). Venta Pendientes usa SOLO esto.
|
||||||
set_lista_pendientes = set(set_vip_actual)
|
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)
|
# Incluir matrículas con override de fecha (igual que ejecutar_consulta_ventas)
|
||||||
_fov_vip = getattr(self.data_manager, '_fecha_canc_overrides', None) or {}
|
_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()]
|
datos_raw = [dict(zip(columns, row)) for row in cursor.fetchall()]
|
||||||
|
|
||||||
# DEDUP por num_matricula: el LEFT JOIN con RP_programa puede duplicar filas
|
# 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,
|
# (una con fch_cancelacion y otra sin). Nos quedamos con UNA sola fila por
|
||||||
# priorizando la que TENGA fecha de cancelación (verdad del pago).
|
# matrícula, priorizando la que TENGA fecha de cancelación (verdad del pago).
|
||||||
_dedup = {}
|
_dedup = {}
|
||||||
for _d in datos_raw:
|
for _d in datos_raw:
|
||||||
_m = str(_d.get('num_matricula', '')).strip()
|
_m = str(_d.get('num_matricula', '')).strip()
|
||||||
@@ -232,7 +232,7 @@ class VentasLogic:
|
|||||||
if _prev is None:
|
if _prev is None:
|
||||||
_dedup[_m] = _d
|
_dedup[_m] = _d
|
||||||
elif _tiene_f and not bool(_prev.get('fch_cancelacion_cuota1')):
|
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())
|
datos_raw = list(_dedup.values())
|
||||||
|
|
||||||
# 🔥 DESCARGA DEL CRONOGRAMA COMPLETO (SIN IMPORTAR EL MES) 🔥
|
# 🔥 DESCARGA DEL CRONOGRAMA COMPLETO (SIN IMPORTAR EL MES) 🔥
|
||||||
@@ -299,17 +299,6 @@ class VentasLogic:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
estado = str(d.get('estado_matricula', '')).strip().upper()
|
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')
|
raw_mat = d.get('num_matricula')
|
||||||
mat_id = ""
|
mat_id = ""
|
||||||
@@ -321,6 +310,20 @@ class VentasLogic:
|
|||||||
try: matricula_int = int(float(val_str))
|
try: matricula_int = int(float(val_str))
|
||||||
except: pass
|
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()
|
dni = str(d.get('dsc_documento', '')).strip()
|
||||||
alumno_nombre = d.get('dsc_alumno', 'SIN NOMBRE')
|
alumno_nombre = d.get('dsc_alumno', 'SIN NOMBRE')
|
||||||
nombre_prog_crudo = str(d.get('dsc_programa', '')).strip().upper()
|
nombre_prog_crudo = str(d.get('dsc_programa', '')).strip().upper()
|
||||||
@@ -633,7 +636,8 @@ class VentasLogic:
|
|||||||
agregar_a_lista("Venta P.C")
|
agregar_a_lista("Venta P.C")
|
||||||
|
|
||||||
# VENTA PENDIENTES: SOLO de tu lista BASE_PENDIENTES y que pagaron su 1ª
|
# 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
|
_pago_mes_real = False
|
||||||
if fch_canc_real_sql and str(fch_canc_real_sql).strip() != "None":
|
if fch_canc_real_sql and str(fch_canc_real_sql).strip() != "None":
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user