diff --git a/backend/modules/cobranza/processor.py b/backend/modules/cobranza/processor.py index 72267af..313f846 100644 --- a/backend/modules/cobranza/processor.py +++ b/backend/modules/cobranza/processor.py @@ -412,21 +412,30 @@ class CobranzaProcessor: stats_resta = {'falla_cuota': 0, 'falla_estado_can': 0, 'falla_nc': 0, 'falla_cancelacion': 0, 'falla_venc_cuota': 0, 'falla_inicio': 0, 'falla_estado_mat': 0, 'falla_treatas': 0, 'pasa_todo': 0} indices_cronograma = set() - mapa_tc = {} - mapa_programa = {} + mapa_tc = {} + mapa_programa = {} mapa_sectorista = {} # <-- NUEVO MAPA PARA CORREGIR ASESORES + # Sectorista puede venir con varios separados por coma (multi). Vacío/TODOS = todos. + _sec_set = {s.strip() for s in str(sectorista_filtro or "TODOS").split(",") if s.strip()} + _sec_all = (not _sec_set) or ("TODOS" in _sec_set) + # Sede/Programa filtro también multi (coma). Vacío/TODOS = todos. + _sede_set = {s.strip().upper() for s in str(sede_filtro or "TODOS").split(",") if s.strip()} + _sede_all = (not _sede_set) or ("TODOS" in _sede_set) + _prog_set = {p.strip().upper() for p in str(prog_filtro or "TODOS").split(",") if p.strip()} + _prog_all = (not _prog_set) or ("TODOS" in _prog_set) + for fila in cronograma_raw: sectorista_str = str(fila.get('dsc_sectorista', '')) sectorista_clean = sectorista_str.strip() - + idx = str(fila.get('num_indice', '')).strip() if idx: # Guardamos el asesor real del cronograma para usarlo en las facturas mapa_sectorista[idx] = sectorista_clean if sectorista_clean and sectorista_clean not in [",", "None"] else "SIN ASESOR" - - if sectorista_clean in [",", "", "None"] or sectorista_str == " , ": continue - if sectorista_filtro != "TODOS" and sectorista_clean != sectorista_filtro: continue + + if sectorista_clean in [",", "", "None"] or sectorista_str == " , ": continue + if not _sec_all and sectorista_clean not in _sec_set: continue if idx: indices_cronograma.add(idx) @@ -450,11 +459,11 @@ class CobranzaProcessor: # Filtro por SEDE y PROGRAMA (REPLACE_META) — se aplica en cualquier # agrupación cuando se pide (usado sobre todo en ASESOR). _prog = fila.get('dsc_programa', '') - if str(sede_filtro).upper() not in ("TODOS", "", "NONE"): - if str(self.clasificar_sede_meta(_prog)).upper() != str(sede_filtro).upper(): + if not _sede_all: + if str(self.clasificar_sede_meta(_prog)).upper() not in _sede_set: continue - if str(prog_filtro).upper() not in ("TODOS", "", "NONE"): - if str(self.clasificar_filtro_programa(_prog)).upper() != str(prog_filtro).upper(): + if not _prog_all: + if str(self.clasificar_filtro_programa(_prog)).upper() not in _prog_set: continue # Filtro por F. Vencimiento (<=). Sin fecha => se incluye siempre. @@ -511,11 +520,11 @@ class CobranzaProcessor: # Mismo filtro SEDE/PROGRAMA (REPLACE_META) que en el cronograma. _progF = fila.get('dsc_programa', '') - if str(sede_filtro).upper() not in ("TODOS", "", "NONE"): - if str(self.clasificar_sede_meta(_progF)).upper() != str(sede_filtro).upper(): + if not _sede_all: + if str(self.clasificar_sede_meta(_progF)).upper() not in _sede_set: continue - if str(prog_filtro).upper() not in ("TODOS", "", "NONE"): - if str(self.clasificar_filtro_programa(_progF)).upper() != str(prog_filtro).upper(): + if not _prog_all: + if str(self.clasificar_filtro_programa(_progF)).upper() not in _prog_set: continue # Filtro por F. Vencimiento (<=). En facturas la fecha es fch_vencimiento_cuota. @@ -671,13 +680,17 @@ class CobranzaProcessor: indices_cronograma = set() mat_validas = set() - mapa_tc = {} - mapa_programa_frec = {} + mapa_tc = {} + mapa_programa_frec = {} + + # Sectorista multi (coma). Vacío/TODOS = todos. + _sec_set = {s.strip() for s in str(sectorista_filtro or "TODOS").split(",") if s.strip()} + _sec_all = (not _sec_set) or ("TODOS" in _sec_set) for fila in cronograma_raw: sectorista_str = str(fila.get('dsc_sectorista', '')).strip() if sectorista_str in [",", ""] or fila.get('dsc_sectorista') == " , ": continue - if sectorista_filtro != "TODOS" and sectorista_str != sectorista_filtro: continue + if not _sec_all and sectorista_str not in _sec_set: continue prog = str(fila.get('dsc_det_programa', '')).strip() if not prog or prog == "None": prog = "SIN PROGRAMA"