- PRECIO and VALORTOTAL are Decimal from fdb driver; convert via _safe_num() - HORAINICIORECEPCION is a datetime object; use _fmt_hora_str() for HH:MM:SS - _parse_hora() now handles datetime objects directly (no str() roundtrip) - Same fixes applied to pacientes.py exam builder - sync-now endpoint catches exceptions and returns traceback as JSON Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from fastapi import APIRouter, Request, Depends, Query
|
|
from fastapi.responses import JSONResponse
|
|
from app.auth import get_current_user
|
|
from app.database import get_connection
|
|
from app.services.scheduler import sync_recientes
|
|
|
|
router = APIRouter(prefix="/envios", tags=["envios"])
|
|
|
|
|
|
@router.get("/tns")
|
|
async def envios_tns(request: Request, user: dict = Depends(get_current_user)):
|
|
return request.app.state.templates.TemplateResponse("envios_tns.html", {
|
|
"request": request, "user": user,
|
|
})
|
|
|
|
|
|
@router.get("/erp")
|
|
async def envios_erp(request: Request, user: dict = Depends(get_current_user)):
|
|
conn = get_connection()
|
|
configs = {row["key"]: row["value"] for row in conn.execute("SELECT * FROM config").fetchall()}
|
|
conn.close()
|
|
wa_url = configs.get("whatsapp_url", "")
|
|
wa_key = configs.get("whatsapp_api_key", "")
|
|
return request.app.state.templates.TemplateResponse("envios_erp.html", {
|
|
"request": request, "user": user,
|
|
"wa_configurado": bool(wa_url and wa_key),
|
|
"wa_url": wa_url,
|
|
})
|
|
|
|
|
|
@router.post("/erp/sync-now")
|
|
async def erp_sync_now(
|
|
ventana_min: int = Query(default=30, ge=1, le=1440),
|
|
user: dict = Depends(get_current_user),
|
|
):
|
|
import traceback as tb
|
|
try:
|
|
resultado = await sync_recientes(ventana_min=ventana_min)
|
|
return JSONResponse(resultado)
|
|
except Exception as e:
|
|
return JSONResponse({"ok": False, "error": str(e), "traceback": tb.format_exc()}, status_code=200)
|