fix: group ventas by NUM_FACTURA, not IDRECEPCION
A single CMXC invoice (e.g. CMXC-307) can have multiple receptions. Previously each reception was sent as a separate ventas, causing TNS to accept the first and reject the rest with "ya existe" — leaving only 1/N of the services registered. Now agrupar_por_factura groups all receptions sharing the same NUM_FACTURA into one ventas JSON with all their services in detallePedido. One factura = one send. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
531fb29122
commit
7f2dffc63e
@@ -125,6 +125,15 @@ def agrupar_por_recepcion(rows: list) -> dict:
|
||||
return grupos
|
||||
|
||||
|
||||
def agrupar_por_factura(rows: list) -> dict:
|
||||
"""Agrupa filas por NUM_FACTURA — para ventas CMXC donde una factura puede tener varias recepciones."""
|
||||
grupos = defaultdict(list)
|
||||
for row in rows:
|
||||
key = str(row.get("NUM_FACTURA") or "")
|
||||
grupos[key].append(dict(row))
|
||||
return grupos
|
||||
|
||||
|
||||
def generar_rda_paciente(rows: list, default_profesional: str = "", default_especialidad: str = "",
|
||||
default_remisionante: str = "00", default_prefijo: str = "00",
|
||||
numero_override: str = "", contrato_map: dict = None,
|
||||
|
||||
Reference in New Issue
Block a user