fix: defensive grouping filter in preview and run ventas endpoints
Replace dict comprehension with explicit loop so that non-list or empty grupo values are safely skipped, preventing KeyError: 0 on v[0]. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3a0964e4ec
commit
c58ecc1757
@@ -455,9 +455,15 @@ async def preview_automation(
|
|||||||
]
|
]
|
||||||
|
|
||||||
grupos_vta_all = agrupar_por_factura(rows_vta)
|
grupos_vta_all = agrupar_por_factura(rows_vta)
|
||||||
grupos_vta = {k: v for k, v in grupos_vta_all.items()
|
grupos_vta = {}
|
||||||
if str(v[0].get("CODCONTRATO") or "").strip() not in excluded_ventas
|
for k, v in grupos_vta_all.items():
|
||||||
and int(v[0].get("NUM_FACTURA") or 0) != 0}
|
if not isinstance(v, list) or not v:
|
||||||
|
continue
|
||||||
|
if int(v[0].get("NUM_FACTURA") or 0) == 0:
|
||||||
|
continue
|
||||||
|
if str(v[0].get("CODCONTRATO") or "").strip() in excluded_ventas:
|
||||||
|
continue
|
||||||
|
grupos_vta[k] = v
|
||||||
|
|
||||||
ventas_preview = []
|
ventas_preview = []
|
||||||
for num_fac_key, grupo_rows in grupos_vta.items():
|
for num_fac_key, grupo_rows in grupos_vta.items():
|
||||||
@@ -734,9 +740,15 @@ async def run_automation(
|
|||||||
# ── PASO 4: Enviar Facturas Venta ─────────────────────────────────────────
|
# ── PASO 4: Enviar Facturas Venta ─────────────────────────────────────────
|
||||||
excluded_ventas = load_excluded_ventas_set()
|
excluded_ventas = load_excluded_ventas_set()
|
||||||
grupos_vta_all = agrupar_por_factura(rows_vta)
|
grupos_vta_all = agrupar_por_factura(rows_vta)
|
||||||
grupos_vta = {k: v for k, v in grupos_vta_all.items()
|
grupos_vta = {}
|
||||||
if str(v[0].get("CODCONTRATO") or "").strip() not in excluded_ventas
|
for k, v in grupos_vta_all.items():
|
||||||
and int(v[0].get("NUM_FACTURA") or 0) != 0}
|
if not isinstance(v, list) or not v:
|
||||||
|
continue
|
||||||
|
if int(v[0].get("NUM_FACTURA") or 0) == 0:
|
||||||
|
continue
|
||||||
|
if str(v[0].get("CODCONTRATO") or "").strip() in excluded_ventas:
|
||||||
|
continue
|
||||||
|
grupos_vta[k] = v
|
||||||
resultado["paso4_ventas"]["excluidos"] = len(grupos_vta_all) - len(grupos_vta)
|
resultado["paso4_ventas"]["excluidos"] = len(grupos_vta_all) - len(grupos_vta)
|
||||||
|
|
||||||
endpoint_venta = f"{TNS_BASE}/v2/facturacion/Ventas/Crear?codigosucursal={api_sucursal or '00'}"
|
endpoint_venta = f"{TNS_BASE}/v2/facturacion/Ventas/Crear?codigosucursal={api_sucursal or '00'}"
|
||||||
|
|||||||
Reference in New Issue
Block a user