From 3b6b40ccd8d7c65076cdb614b65a012628536032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Tue, 30 Jun 2026 12:14:49 -0600 Subject: [PATCH] =?UTF-8?q?fix(cobranza):=20quita=20la=20leyenda=20"Incluy?= =?UTF-8?q?e=20contratos=20con=20d=C3=ADa=2029/30/31..."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La leyenda aparecía siempre que la búsqueda agregaba días huérfanos (fin de mes), aunque ningún contrato cayera en un día inexistente (p. ej. 30 de junio mostraba la leyenda sin contratos de día 31). Confundía. Se elimina la leyenda del reporte diario (_formatear_reporte) y semanal (_formatear_reporte_semanal). No se toca la lógica: el flag incluye_orfanos sigue calculándose en sheets.generar_reporte_cobros; solo deja de renderizarse. Rentas, montos, VR, extras y el recorrido huérfano→último día→lunes intactos. tests/test_leyenda_orfanos.py: la leyenda no aparece ni con incluye_orfanos=True (diario y semanal). 32 tests OK. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/api/webhook.py | 4 ---- tests/test_leyenda_orfanos.py | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 tests/test_leyenda_orfanos.py diff --git a/src/api/webhook.py b/src/api/webhook.py index 91ba9de..3c49d99 100644 --- a/src/api/webhook.py +++ b/src/api/webhook.py @@ -1669,8 +1669,6 @@ def _formatear_reporte(reporte: dict) -> str: encabezado = f"📋 *Cobros — {_fecha_larga_es(fecha)}*" if es_lunes: encabezado += "\n_(incluye sáb-dom)_" - if reporte.get("incluye_orfanos"): - encabezado += "\nℹ️ _Incluye contratos con día 29/30/31 que no existen este mes_" partes.append(encabezado) # Sección 1 — rentas del día (siempre presente) @@ -1789,8 +1787,6 @@ def _formatear_reporte_semanal(reporte: dict) -> str: encabezado = f"📋 *Cobranza semanal — {_rango_semana_es(lunes, viernes)}*" else: encabezado = "📋 *Cobranza semanal*" - if reporte.get("incluye_orfanos"): - encabezado += "\nℹ️ _Incluye contratos con día 29/30/31 que no existen este mes_" partes: list[str] = [encabezado] diff --git a/tests/test_leyenda_orfanos.py b/tests/test_leyenda_orfanos.py new file mode 100644 index 0000000..97278a6 --- /dev/null +++ b/tests/test_leyenda_orfanos.py @@ -0,0 +1,43 @@ +""" +La leyenda informativa "Incluye contratos con día 29/30/31 que no existen este +mes" se removió: ya NO debe aparecer en el reporte, ni siquiera cuando el +reporte trae incluye_orfanos=True. Solo se valida la presencia/ausencia de la +leyenda; no se toca el cálculo de rentas/VR/extras. +""" +import os +from datetime import date + +os.environ.setdefault("OPENAI_API_KEY", "test-key-no-usada") + +from src.api.webhook import _formatear_reporte, _formatear_reporte_semanal + +LEYENDA = "29/30/31" # fragmento único de la leyenda removida + + +def test_leyenda_no_aparece_diario(): + reporte = { + "fecha": date(2026, 6, 30), + "es_lunes": False, + "rentas": [], + "vr": [], + "extras": [], + "incluye_orfanos": True, # aunque venga True, NO debe imprimirse la leyenda + } + texto = _formatear_reporte(reporte) + assert LEYENDA not in texto + assert "no existen este mes" not in texto + + +def test_leyenda_no_aparece_semanal(): + reporte = { + "fecha": date(2026, 6, 29), + "lunes": date(2026, 6, 29), + "viernes": date(2026, 7, 3), + "rentas_por_dia": {}, + "vr": [], + "extras": [], + "incluye_orfanos": True, + } + texto = _formatear_reporte_semanal(reporte) + assert LEYENDA not in texto + assert "no existen este mes" not in texto