debug: add /debug-fb/facturas endpoint to search by NUM_FACTURA range

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-28 16:13:02 -05:00
co-authored by Claude Sonnet 4.6
parent 55bb34a1fa
commit 9dd234e124
+42
View File
@@ -349,6 +349,48 @@ async def debug_preview_ventas(
return JSONResponse({"ok": False, "traceback": traceback.format_exc()})
@router.get("/facturas")
async def debug_facturas(
desde: int = Query(..., description="NUM_FACTURA desde"),
hasta: int = Query(..., description="NUM_FACTURA hasta"),
user: dict = Depends(get_current_user),
):
"""Busca recepciones por rango de NUM_FACTURA en Firebird."""
try:
conn = get_connection()
cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
conn.close()
fb, ok, msg = get_firebird_from_config(cfg)
if not ok:
return JSONResponse({"ok": False, "error": msg})
ok1, _, rows = fb.execute_query("""
SELECT
r.IDRECEPCION, TRIM(r.PREFIJO) AS PREFIJO, r.NUM_FACTURA,
CAST(r.FECHA_RECEPCION AS VARCHAR(30)) AS FECHA_RECEPCION,
r.COD_PACIENTE,
TRIM(r.NIT_EMPRESA) AS NIT_EMPRESA,
TRIM(e.CODCONTRATO) AS CODCONTRATO,
TRIM(e.NOMBRE) AS NOM_EMPRESA,
(SELECT COUNT(*) FROM RELACION rel WHERE rel.IDRECEPCION = r.IDRECEPCION) AS N_EXAMENES
FROM RECEPCION r
LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA
WHERE r.NUM_FACTURA BETWEEN ? AND ?
ORDER BY r.NUM_FACTURA, r.IDRECEPCION
""", (desde, hasta))
fb.disconnect()
return JSONResponse({
"ok": ok1,
"desde": desde,
"hasta": hasta,
"count": len(rows or []),
"rows": list(rows or []),
})
except Exception:
return JSONResponse({"ok": False, "traceback": traceback.format_exc()})
@router.get("/cups")
async def find_cups(request: Request, user: dict = Depends(get_current_user)):
try: