Actualizar backend/services.py
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user