debug: ampliar debug-cmxc para mostrar envios del dia
This commit is contained in:
@@ -147,16 +147,18 @@ async def automation_page(request: Request, user: dict = Depends(get_current_use
|
|||||||
|
|
||||||
@router.get("/debug-cmxc")
|
@router.get("/debug-cmxc")
|
||||||
async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), fecha: str = ""):
|
async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), fecha: str = ""):
|
||||||
"""Diagnóstico temporal: muestra recepciones CMXC para una fecha."""
|
"""Diagnóstico temporal: muestra recepciones CMXC y sus envíos para una fecha."""
|
||||||
conn = get_connection()
|
if not fecha:
|
||||||
configs = {row["key"]: row["value"] for row in conn.execute("SELECT * FROM config").fetchall()}
|
fecha = date.today().isoformat()
|
||||||
conn.close()
|
|
||||||
|
# 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)
|
fb, fb_ok, fb_msg = get_firebird_from_config(configs)
|
||||||
if not fb_ok:
|
if not fb_ok:
|
||||||
return JSONResponse({"error": fb_msg})
|
return JSONResponse({"error": fb_msg})
|
||||||
if not fecha:
|
ok, err, rows_fb = fb.execute_query("""
|
||||||
fecha = date.today().isoformat()
|
|
||||||
ok, err, rows = fb.execute_query("""
|
|
||||||
SELECT r.IDRECEPCION, r.PREFIJO, r.NUM_FACTURA, r.PS_NUM,
|
SELECT r.IDRECEPCION, r.PREFIJO, r.NUM_FACTURA, r.PS_NUM,
|
||||||
r.NIT_EMPRESA, r.VALORTOTAL, r.FECHA_RECEPCION
|
r.NIT_EMPRESA, r.VALORTOTAL, r.FECHA_RECEPCION
|
||||||
FROM RECEPCION r
|
FROM RECEPCION r
|
||||||
@@ -167,7 +169,22 @@ async def debug_cmxc(request: Request, user: dict = Depends(get_current_user), f
|
|||||||
fb.disconnect()
|
fb.disconnect()
|
||||||
if not ok:
|
if not ok:
|
||||||
return JSONResponse({"error": err})
|
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):
|
def _build_sql(contrato: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user