From cab70a439f51a64abc378768ff2dcb78ad90c827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Sat, 14 Nov 2026 21:54:59 -0600 Subject: [PATCH] feat(carga): el historial de cargas descarga el archivo original de cada lote, con la huella verificada --- app/routers/carga.py | 1 + app/templates/carga/index.html | 7 +++++-- tests/test_lote_archivo.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/routers/carga.py b/app/routers/carga.py index cde17aa..6da251e 100644 --- a/app/routers/carga.py +++ b/app/routers/carga.py @@ -73,6 +73,7 @@ def modulo(request: Request, db: Annotated[Session, Depends(get_db)]) -> HTMLRes "vencida": servicio.carga_vencida(db, tenant), "periodo_meses": tenant.periodo_carga_meses, "historial": (historial := servicio.historial_cargas(db)), + "puede_descargar_original": request.state.usuario.rol in ROLES_ORIGINAL, "estados": { lote.id: servicio.estado_visible(lote) for lote in [*historial, servicio.ultima_carga(db, tenant)] diff --git a/app/templates/carga/index.html b/app/templates/carga/index.html index a4ed364..f59519c 100644 --- a/app/templates/carga/index.html +++ b/app/templates/carga/index.html @@ -60,7 +60,7 @@ {% call tarjeta("Historial de cargas", subtitulo=historial | length ~ " lotes, el más reciente primero", plano=True) %}
- + {%- for lote in historial %}{% set d = lote.filas or {} %} @@ -71,7 +71,10 @@ - + {%- else %} diff --git a/tests/test_lote_archivo.py b/tests/test_lote_archivo.py index 3c4d951..18de402 100644 --- a/tests/test_lote_archivo.py +++ b/tests/test_lote_archivo.py @@ -177,3 +177,15 @@ def test_evidencia_liga_cada_dato_con_su_lote_y_su_archivo(fabrica, cliente: Tes assert f'data-original-lote="{lote_id}"' in pagina assert NOMBRE in pagina assert "alta del cliente, 1 crédito, 1 pago" in pagina + + +def test_el_historial_de_cargas_descarga_el_original(fabrica, cliente: TestClient) -> None: + contenido = xlsx(COMPLETO()) + entrar_empresa(cliente, Rol.OFICIAL) + lote_id = subir(cliente, contenido) + for rol in (Rol.OFICIAL, Rol.ANALISTA, Rol.AUDITOR): + cliente.post("/logout") + entrar_empresa(cliente, rol) + historial = cliente.get("/carga").text + assert f'href="/carga/lotes/{lote_id}/original"' in historial + assert cliente.get(f"/carga/lotes/{lote_id}/original").content == contenido
LoteFechaUsuarioArchivoEstadoAceptadasRechazadasRechazos
LoteFechaUsuarioArchivoEstadoAceptadasRechazadasArchivo original y rechazos
{{ estado_lote(lote, estados.get(lote.id)) }} {{ d.get("aceptadas", d.get("transacciones_cargadas", "—")) }} {{ d.get("rechazadas", (lote.errores or []) | length) }}{% if d.get("rechazadas") %}Rechazos{% endif %} + {%- if d.get("rechazadas") %}Rechazos{% endif %} + {%- if puede_descargar_original and lote.ruta_archivo %}Original{% endif -%} +
Todavía no hay cargas.