fix(cobranza): ordena VR y extraordinarias por fecha de vencimiento

Las secciones de Valor Residual y Rentas Extraordinarias del reporte se
agregaban en orden de fila del Sheet. Ahora se ordenan por su fecha
(fecha_vr / fecha_extra) y alfabético por cliente en empate. Aplica a todos
los días. Solo ordenamiento; montos, totales y filas intactos.

tests/test_reporte_orden.py: verifica el orden por fecha de VR y extras.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jorem JuárezandClaude Opus 4.8 committed 2026-06-29 12:21:48 -06:00
1 parent 3d1c25b4f2
commit 6db44f502f
2 files changed
+46

No files matched your search

+4
View File
@@ -993,6 +993,10 @@ def generar_reporte_cobros(
),
})
# Orden cronológico por fecha de vencimiento (y alfabético en empate).
vr_items.sort(key=lambda v: (v.get("fecha_vr") or date.max, v.get("cliente", "")))
extras.sort(key=lambda e: (e.get("fecha_extra") or date.max, e.get("cliente", "")))
return {
"fecha": hoy,
"es_lunes": es_lunes,
+42
View File
@@ -54,3 +54,45 @@ def test_lunes_ordena_cronologico(mock_get_client):
("ALPHA", 29), # lunes, alfabético dentro del día
("ZETA", 29),
]
def _fila_vr(cliente, fecha_ddmmaaaa, total="100000"):
f = [""] * 23
f[1] = cliente
f[2] = "VEHICULO"
f[11] = total # _IDX_VR_TOTAL
f[13] = "" # plazo vacío → monto_a_cobrar = total
f[18] = f"({fecha_ddmmaaaa})" # _IDX_FECHAS_VR
return f
def _fila_extra(cliente, fecha_ddmmaaaa, monto="$5,000"):
f = [""] * 23
f[1] = cliente
f[2] = "VEHICULO"
f[16] = monto # _IDX_NOTAS (de donde se extrae el monto)
f[19] = f"({fecha_ddmmaaaa})" # _IDX_FECHAS_EXTRA
return f
@patch.object(sheets, "_IDX_TASA_MORATORIA_CACHE", None)
@patch.object(sheets, "_gc", None)
@patch.object(sheets, "_get_client")
def test_vr_y_extras_ordenan_por_fecha(mock_get_client):
rows = [
HEADER,
_fila_vr("C-VR-30", "30/06/2026"),
_fila_vr("C-VR-15", "15/06/2026"),
_fila_vr("C-VR-17", "17/06/2026"),
_fila_extra("C-EX-22", "22/06/2026"),
_fila_extra("C-EX-05", "05/06/2026"),
]
mock_get_client.return_value = _mock_gc(rows)
reporte = sheets.generar_reporte_cobros(hoy=date(2026, 6, 29))
vr_fechas = [v["fecha"] for v in reporte["vr"]]
assert vr_fechas == ["15/06/2026", "17/06/2026", "30/06/2026"]
ex_fechas = [e["fecha"] for e in reporte["extras"]]
assert ex_fechas == ["05/06/2026", "22/06/2026"]