From 531fb291228ca640b90a930677b9d1ee087bb03c Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 26 Jul 2026 21:45:14 -0500 Subject: [PATCH] fix: group terceros by cedula not fecha-as-factura For terceros, _guardar_envio stores the automation date in the factura field (not a patient id), so COALESCE(factura, cedula) still collapsed all terceros into one row. Now GROUP BY uses cedula for tipo=terceros and factura for transaccion/ventas. Template hides the date in the factura column for terceros rows. Co-Authored-By: Claude Sonnet 4.6 --- app/routes/logs.py | 4 ++-- app/templates/resumen.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/routes/logs.py b/app/routes/logs.py index 8c4c9e1..76fa992 100644 --- a/app/routes/logs.py +++ b/app/routes/logs.py @@ -236,8 +236,8 @@ async def resumen_page( END AS estado_final FROM envios WHERE DATE(created_at) = ? {where_extra} - GROUP BY COALESCE(NULLIF(factura, ''), cedula), tipo - ORDER BY estado_final, tipo, COALESCE(factura, cedula) + GROUP BY CASE WHEN tipo = 'terceros' THEN cedula ELSE factura END, tipo + ORDER BY estado_final, tipo, CASE WHEN tipo = 'terceros' THEN cedula ELSE factura END """, params_q).fetchall() conn.close() diff --git a/app/templates/resumen.html b/app/templates/resumen.html index cb38765..b8c1240 100644 --- a/app/templates/resumen.html +++ b/app/templates/resumen.html @@ -98,7 +98,7 @@ {{ r.tipo }} - {{ r.factura or '—' }} + {{ '—' if r.tipo == 'terceros' else (r.factura or '—') }} {{ r.idrecepcion or '—' }} {{ r.contrato or '—' }} {{ r.cedula or '—' }}