From a8d416b9383d89f0da5ade9885dac01d148a8566 Mon Sep 17 00:00:00 2001 From: Fernando Davila Date: Fri, 9 Oct 2026 11:41:36 -0600 Subject: [PATCH] feat(operaciones): inicio de la ventana vigente en la pantalla de cierre MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GET /operaciones/cierre suma inicio_ventana_vigente (aggregates.inicio_ventana sobre el corte actual y la ventana del tenant, como Inicio) para dibujar la ventana vigente junto a la nueva. La lógica del cierre no cambia. --- app/routers/operaciones.py | 8 +++++++- tests/test_operaciones.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/routers/operaciones.py b/app/routers/operaciones.py index b6c5f59..c9ac1c3 100644 --- a/app/routers/operaciones.py +++ b/app/routers/operaciones.py @@ -24,6 +24,7 @@ from starlette.responses import HTMLResponse, RedirectResponse, Response from app.auth import requiere_rol from app.db import get_db +from app.engine.aggregates import inicio_ventana from app.importers.operations import TAMANO_MAXIMO_BYTES from app.models import Usuario from app.models.usuario import Rol @@ -173,11 +174,16 @@ def _cierre( justificacion: str = "", status_code: int = 200, ) -> HTMLResponse: + plan = servicio_periodo.plan_de_cierre(db, fecha_hoy=servicio_periodo.hoy()) return render( request, "operaciones/cierre.html", { - "plan": servicio_periodo.plan_de_cierre(db, fecha_hoy=servicio_periodo.hoy()), + "plan": plan, + # Para dibujar la ventana vigente junto a la nueva (como en Inicio). + "inicio_ventana_vigente": inicio_ventana( + plan.corte_actual, request.state.tenant.ventana_meses + ), "puede_cerrar": request.state.usuario.rol in ROLES_CIERRE, "error": error, "justificacion": justificacion, diff --git a/tests/test_operaciones.py b/tests/test_operaciones.py index 4d993b0..f833671 100644 --- a/tests/test_operaciones.py +++ b/tests/test_operaciones.py @@ -633,6 +633,8 @@ def test_cierre_por_http_exige_confirmacion_y_justificacion(cliente: TestClient, pantalla = cliente.get("/operaciones/cierre") assert pantalla.status_code == 200 assert "irreversible" in pantalla.text and "/data/pld.db" in pantalla.text + # Corte vigente 31/08/2026 con ventana de 6 meses: (28/02/2026, 31/08/2026]. + assert pantalla.context["inicio_ventana_vigente"] == date(2026, 2, 28) assert ( cliente.post( "/operaciones/cierre", data={"justificacion": "Sin marcar la casilla de confirmación."}