fix(automation): excluir ventas con NUM_FACTURA=0 (numero 00000)

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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-11 15:22:46 -05:00
co-authored by Claude Sonnet 4.6
parent 6dee8fba82
commit c584097426
+6 -2
View File
@@ -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)