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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-26 21:45:14 -05:00
co-authored by Claude Sonnet 4.6
parent 4b70f6f2fa
commit 531fb29122
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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()
+1 -1
View File
@@ -98,7 +98,7 @@
{{ r.tipo }}
</span>
</td>
<td class="px-2 py-2.5 text-gray-700 font-medium">{{ r.factura or '—' }}</td>
<td class="px-2 py-2.5 text-gray-700 font-medium">{{ '—' if r.tipo == 'terceros' else (r.factura or '—') }}</td>
<td class="px-2 py-2.5 text-gray-500 font-mono">{{ r.idrecepcion or '—' }}</td>
<td class="px-2 py-2.5 text-gray-500">{{ r.contrato or '—' }}</td>
<td class="px-2 py-2.5 text-gray-500 font-mono">{{ r.cedula or '—' }}</td>