From 3aa07543dbd68ba8758c260e4f68826388e9826d Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:51:16 -0500 Subject: [PATCH] debug: endpoint temporal /automation/debug-cmxc para diagnosticar recepciones CMXC Co-Authored-By: Claude Sonnet 4.6 --- app/routes/automation.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/routes/automation.py b/app/routes/automation.py index 6c3f008..b64b57c 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -145,6 +145,31 @@ async def automation_page(request: Request, user: dict = Depends(get_current_use }) +@router.get("/debug-cmxc") +async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), fecha: str = ""): + """Diagnóstico temporal: muestra recepciones CMXC para una fecha.""" + conn = get_connection() + configs = {row["key"]: row["value"] for row in conn.execute("SELECT * FROM config").fetchall()} + conn.close() + fb, fb_ok, fb_msg = get_firebird_from_config(configs) + if not fb_ok: + return JSONResponse({"error": fb_msg}) + if not fecha: + fecha = date.today().isoformat() + ok, err, rows = fb.execute_query(""" + SELECT r.IDRECEPCION, r.PREFIJO, r.NUM_FACTURA, r.PS_NUM, + r.NIT_EMPRESA, r.VALORTOTAL, r.FECHA_RECEPCION + FROM RECEPCION r + WHERE r.FECHA_RECEPCION BETWEEN ? AND ? + AND r.PREFIJO = 'CMXC' + ORDER BY r.IDRECEPCION + """, {"fecha_ini": f"{fecha} 00:00:00", "fecha_fin": f"{fecha} 23:59:59"}) + fb.disconnect() + if not ok: + return JSONResponse({"error": err}) + return JSONResponse({"fecha": fecha, "total": len(rows), "rows": rows}) + + def _build_sql(contrato: str): if contrato: fp = "AND e.CODCONTRATO = :contrato"