From c5840974268878bde9d704d0b4f68e299ac0cd9d Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 11 Jul 2026 15:22:46 -0500 Subject: [PATCH] fix(automation): excluir ventas con NUM_FACTURA=0 (numero 00000) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No enviar facturas cuyo número sea 0 — quedarían como "00000" en TNS. Filtro aplicado en preview, run y reenviar-venta. Co-Authored-By: Claude Sonnet 4.6 --- app/routes/automation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/routes/automation.py b/app/routes/automation.py index 4ee4c3d..8951468 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -452,7 +452,8 @@ async def preview_automation( grupos_vta_all = agrupar_por_recepcion(rows_vta) grupos_vta = {k: v for k, v in grupos_vta_all.items() - if str(v[0].get("CODCONTRATO") or "").strip() not in excluded_ventas} + if str(v[0].get("CODCONTRATO") or "").strip() not in excluded_ventas + and int(v[0].get("NUM_FACTURA") or 0) != 0} ventas_preview = [] for id_rec, grupo_rows in grupos_vta.items(): @@ -704,7 +705,8 @@ async def run_automation( excluded_ventas = load_excluded_ventas_set() grupos_vta_all = agrupar_por_recepcion(rows_vta) grupos_vta = {k: v for k, v in grupos_vta_all.items() - if str(v[0].get("CODCONTRATO") or "").strip() not in excluded_ventas} + if str(v[0].get("CODCONTRATO") or "").strip() not in excluded_ventas + and int(v[0].get("NUM_FACTURA") or 0) != 0} resultado["paso4_ventas"]["excluidos"] = len(grupos_vta_all) - len(grupos_vta) endpoint_venta = f"{TNS_BASE}/v2/facturacion/Ventas/Crear" @@ -930,6 +932,8 @@ async def reenviar_venta( contrato_vta = str(rows[0].get("CODCONTRATO") or "").strip() if contrato_vta in excluded_ventas: return JSONResponse({"success": False, "message": f"Contrato {contrato_vta} excluido"}) + if int(rows[0].get("NUM_FACTURA") or 0) == 0: + return JSONResponse({"success": False, "message": "Factura sin número asignado (00000)"}) from collections import defaultdict grupos: dict = defaultdict(list)