From 4b70f6f2fa3857ec84f8670e51fe0fad34e14cbd Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 26 Jul 2026 21:34:45 -0500 Subject: [PATCH] fix: resumen - group terceros by cedula, prioritize success over warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GROUP BY COALESCE(factura, cedula) fixes terceros (factura=NULL) collapsing into one row — each paciente now gets its own row. CASE WHEN in estado_final explicitly prioritizes success > warning > error instead of relying on alphabetical MAX which returned warning over success. Co-Authored-By: Claude Sonnet 4.6 --- app/routes/logs.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/routes/logs.py b/app/routes/logs.py index b7457d1..8c4c9e1 100644 --- a/app/routes/logs.py +++ b/app/routes/logs.py @@ -229,14 +229,15 @@ async def resumen_page( MAX(created_at) AS ultimo_envio, MAX(CASE WHEN status = 'error' THEN id END) AS ultimo_error_id, MAX(CASE WHEN status != 'error' THEN id END) AS exitoso_id, - CASE WHEN SUM(CASE WHEN status != 'error' THEN 1 ELSE 0 END) > 0 - THEN MAX(CASE WHEN status != 'error' THEN status END) - ELSE 'error' + CASE + WHEN SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) > 0 THEN 'success' + WHEN SUM(CASE WHEN status = 'warning' THEN 1 ELSE 0 END) > 0 THEN 'warning' + ELSE 'error' END AS estado_final FROM envios WHERE DATE(created_at) = ? {where_extra} - GROUP BY factura, tipo - ORDER BY estado_final, tipo, factura + GROUP BY COALESCE(NULLIF(factura, ''), cedula), tipo + ORDER BY estado_final, tipo, COALESCE(factura, cedula) """, params_q).fetchall() conn.close()