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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-28 15:10:59 -05:00
co-authored by Claude Sonnet 4.6
parent c58ecc1757
commit b8bee68d6a
+17 -5
View File
@@ -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,