From 71c4d1376eb8bb2d203be9f8f4e4ae371175f508 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 30 Jun 2026 17:24:09 -0500 Subject: [PATCH] Actualizar backend/services.py --- backend/services.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/backend/services.py b/backend/services.py index bc34d4d..797ff3d 100644 --- a/backend/services.py +++ b/backend/services.py @@ -81,6 +81,32 @@ def ventas(ano, mes, sede="TODOS", programa="TODOS"): if hasattr(logic, "obtener_datos_brutos_filtrado") else logic.obtener_datos_brutos(str(ano), mes_padded) datos = [d for d in (datos or []) if d.get('VENDEDOR', 'SIN VENDEDOR') != 'SIN VENDEDOR'] + + # PENDIENTES: recalcular desde el MISMO detalle del "Ver" (__TODOS__), para que + # la tabla principal y el popup Ver salgan SIEMPRE idénticos (misma fuente/regla). + try: + det = logic.obtener_detalle_vendedor("__TODOS__", str(ano), mes_str) + pend_filas = det.get("Venta Pendientes", []) if isinstance(det, dict) else [] + pend_por_vend = {} + for f in pend_filas: + if not f or str(f[0]).strip().upper() == "TOTAL GENERAL": + continue + vend = str(f[0]).strip() + try: + monto = float(str(f[7]).replace("S/", "").replace(",", "").strip()) + except Exception: + monto = 0.0 + acc = pend_por_vend.setdefault(vend, {"monto": 0.0, "cant": 0}) + acc["monto"] += monto + acc["cant"] += 1 + for d in datos: + v = str(d.get("VENDEDOR", "")).strip() + acc = pend_por_vend.get(v, {"monto": 0.0, "cant": 0}) + d["PENDIENTES"] = round(acc["monto"], 2) + d["INSCRITOS_PENDIENTES"] = acc["cant"] + except Exception as e: + print(f"[ventas] no se pudo alinear PENDIENTES con el Ver: {e}") + filas = logic.formatear_datos_para_tabla(datos) print(f"[DEBUG Ventas] Proceso completado. Registros encontrados: {len(datos)}") return {