From b8bee68d6a1a84940cad45d89501df036300f5c0 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:10:59 -0500 Subject: [PATCH] debug: expose ventas filter info in preview response ventas_raw = filas de Firebird antes de filtrar ventas_grupos_total = grupos por factura antes del filtro ventas_filtradas = grupos excluidos con motivo (sin_factura / excluido_ventas) Co-Authored-By: Claude Sonnet 4.6 --- app/routes/automation.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/routes/automation.py b/app/routes/automation.py index 72da592..6178c52 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -455,15 +455,24 @@ async def preview_automation( ] grupos_vta_all = agrupar_por_factura(rows_vta) + ventas_debug = [] grupos_vta = {} for k, v in grupos_vta_all.items(): if not isinstance(v, list) or not v: continue - if int(v[0].get("NUM_FACTURA") or 0) == 0: - continue - if str(v[0].get("CODCONTRATO") or "").strip() in excluded_ventas: - continue - grupos_vta[k] = v + num_fac_val = int(v[0].get("NUM_FACTURA") or 0) + contrato_val = str(v[0].get("CODCONTRATO") or "").strip() + prefijo_val = str(v[0].get("PREFIJO") or "").strip() + motivo = None + if num_fac_val == 0: + motivo = "sin_factura" + elif contrato_val in excluded_ventas: + motivo = f"excluido_ventas ({contrato_val})" + if motivo: + ventas_debug.append({"key": k, "prefijo": prefijo_val, "num_factura": num_fac_val, + "contrato": contrato_val, "motivo": motivo}) + else: + grupos_vta[k] = v ventas_preview = [] for num_fac_key, grupo_rows in grupos_vta.items(): @@ -489,6 +498,9 @@ async def preview_automation( "excluidos": excluidos_count, "preservicios": len(grupos_ps), "ventas": len(grupos_vta), + "ventas_raw": len(rows_vta or []), + "ventas_grupos_total": len(grupos_vta_all), + "ventas_filtradas": ventas_debug, "pacientes_preview": pacientes_preview, "preservicios_preview": preservicios_preview, "ventas_preview": ventas_preview,