debug: ampliar debug-cmxc para mostrar envios del dia

This commit is contained in:
Lizandro Guarnizo
2026-07-10 21:04:55 -05:00
parent fd2a107353
commit 34b112919c
+25 -8
View File
@@ -147,16 +147,18 @@ 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()
"""Diagnóstico temporal: muestra recepciones CMXC y sus envíos para una fecha."""
if not fecha:
fecha = date.today().isoformat()
# Recepciones CMXC en Firebird
conn_cfg = get_connection()
configs = {row["key"]: row["value"] for row in conn_cfg.execute("SELECT * FROM config").fetchall()}
conn_cfg.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("""
ok, err, rows_fb = 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
@@ -167,7 +169,22 @@ async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), f
fb.disconnect()
if not ok:
return JSONResponse({"error": err})
return JSONResponse({"fecha": fecha, "total": len(rows), "rows": rows})
# Envíos del día en SQLite
conn_sq = get_connection()
envios = conn_sq.execute("""
SELECT factura, status, respuesta_api, mensaje_tns, created_at
FROM envios
WHERE DATE(created_at) = ? AND tipo IN ('rda','preserv')
ORDER BY id DESC
""", (fecha,)).fetchall()
conn_sq.close()
return JSONResponse({
"fecha": fecha,
"cmxc_firebird": {"total": len(rows_fb), "rows": rows_fb},
"envios_dia": [dict(e) for e in envios],
})
def _build_sql(contrato: str):