fix: resumen - group terceros by cedula, prioritize success over warning
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
6e9ee32646
commit
4b70f6f2fa
+6
-5
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user