feat(cobranza): lote con conceptos individuales y selección masiva

Cobrar en lote:
- Se elimina el campo "Concepto del lote".
- Cada cobro usa su concepto individual (autoConcepto del renglón), enviado
  por fila al backend. autoConcepto ahora usa la etiqueta en tipo "otro"
  (ej. WK-TENENCIA-CLIENTE-JUN26) en vez de "OTRO".
- Botón "Seleccionar/Deseleccionar todos" (solo afecta renglones con número;
  los sin número no entran a la selección masiva).
- (fix previo) autoselección y badge usan telefono_efectivo (override O
  directorio), no solo el override local.

Backend: LoteFila.concepto opcional + CobrarLoteBody.concepto opcional;
cobrar_lote usa el concepto por fila (cae al global si la fila no trae uno).
Retrocompatible. 22 tests OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jorem JuárezandClaude Opus 4.8 committed 2026-06-24 13:58:01 -06:00
1 parent c991ed7779
commit fba9785fd3
2 files changed
+36 -14

No files matched your search

+7 -3
View File
@@ -187,10 +187,11 @@ class LoteFila(BaseModel):
id: str
tipo: str # "saldo" | "sinmora" | "personal"
monto: float | None = None
concepto: str | None = None # concepto individual del renglón (opcional)
class CobrarLoteBody(BaseModel):
concepto: str
concepto: str = "" # fallback global; cada fila puede traer el suyo
filas: list[LoteFila]
@@ -562,9 +563,12 @@ async def cobrar_lote(body: CobrarLoteBody, token: str = Query(...)):
if not tel_efectivo:
omitidos_sin_tel.append(r.get("cliente", fila.id))
continue
# Concepto individual del renglón; cae al global solo si la fila no
# trae uno propio.
concepto_fila = (fila.concepto or "").strip() or body.concepto or ""
try:
cobro = await _generar_cobro_para_renglon(
numero, r, fila.tipo, fila.monto, body.concepto,
numero, r, fila.tipo, fila.monto, concepto_fila,
)
except HTTPException as e:
logger.warning("Lote: error en %s: %s", fila.id, e.detail)
@@ -577,7 +581,7 @@ async def cobrar_lote(body: CobrarLoteBody, token: str = Query(...)):
texto = _mensaje_cobro(
cliente=r.get("cliente", ""),
vehiculo=r.get("vehiculo", ""),
concepto=body.concepto,
concepto=concepto_fila,
monto=cobro["monto"],
link=cobro["link"],
)
+29 -11
View File
@@ -1429,8 +1429,9 @@ async function cancelarAbono(idRenglon, idAbono){
function abrirLote(){
if(!renglones.length){ toast("No hay renglones activos"); return; }
loteState = {
concepto: "Pago WK Financing",
filas: renglones.map(r => ({ id:r.id, incluido: !!r.telefono, tipo:"saldo", montoPersonal:"" })),
// Autoseleccionar los que YA tienen teléfono efectivo (override O directorio),
// no solo el override local.
filas: renglones.map(r => ({ id:r.id, incluido: !!(r.telefono_efectivo || r.telefono), tipo:"saldo", montoPersonal:"" })),
};
renderLote();
document.getElementById("modal").classList.add("open");
@@ -1450,7 +1451,7 @@ function renderLote(){
const r = _findR(f.id); if(!r) return "";
const conI = Number(r.saldo)||0;
const sinI = (Number(r.capital)||0) - (Number(r.abonado)||0);
const sinNum = !r.telefono;
const sinNum = !(r.telefono_efectivo || r.telefono);
return `
<div class="lote-row ${f.incluido?'':'off'}">
<div class="lote-row-head">
@@ -1468,14 +1469,14 @@ function renderLote(){
: ''}
</div>`;
}).join("");
const selables = loteState.filas.filter(f => { const r = _findR(f.id); return r && (r.telefono_efectivo || r.telefono); });
const todosSel = selables.length > 0 && selables.every(f => f.incluido);
inner.innerHTML = `
<div class="modal-header"><span class="modal-title">Cobrar en lote</span><button class="modal-close" onclick="cerrar()">×</button></div>
<div class="form-group">
<label class="form-label">Concepto del lote</label>
<input type="text" class="form-input" id="lote-concepto" value="${loteState.concepto}" oninput="loteState.concepto=this.value">
<div class="form-hint">Se usa para todos los cobros del lote</div>
<div style="display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px">
<span class="section-label" style="margin:0">${loteState.filas.length} renglones · elige el tipo de cobro</span>
<button onclick="toggleLoteTodos()" style="background:transparent;border:none;color:var(--accent);font-size:11.5px;font-weight:700;letter-spacing:0.3px;cursor:pointer;white-space:nowrap;padding:4px 2px">${todosSel ? "Deseleccionar todos" : "Seleccionar todos"}</button>
</div>
<div class="section-label">${loteState.filas.length} renglones · elige el tipo de cobro</div>
${rows}
<div class="lote-summary"><span class="lt"><span id="lote-count">0</span> seleccionados</span><span class="lv" id="lote-total">$0</span></div>
<button class="btn-cliente" onclick="enviarLote()"><svg class="ic" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z"/></svg> Enviar cobros automáticamente</button>`;
@@ -1483,6 +1484,15 @@ function renderLote(){
}
function setLoteTipo(i,t){ loteState.filas[i].tipo = t; renderLote(); }
function toggleLote(i){ loteState.filas[i].incluido = !loteState.filas[i].incluido; renderLote(); }
// Selecciona/deselecciona todos los que tienen número (los sin número no se
// pueden enviar, así que quedan fuera de la selección masiva).
function toggleLoteTodos(){
const tiene = (f) => { const r = _findR(f.id); return !!(r && (r.telefono_efectivo || r.telefono)); };
const selables = loteState.filas.filter(tiene);
const todosSel = selables.length > 0 && selables.every(f => f.incluido);
loteState.filas.forEach(f => { f.incluido = todosSel ? false : tiene(f); });
renderLote();
}
function setLotePersonal(i,v){ loteState.filas[i].montoPersonal = v; actualizarLoteSummary(); }
function actualizarLoteSummary(){
let total = 0, n = 0;
@@ -1501,9 +1511,11 @@ async function enviarLote(){
const filas = incluidas.map(f => ({
id: f.id, tipo: f.tipo,
monto: f.tipo === "personal" ? parseFloat(f.montoPersonal) : null,
// Concepto individual de cada renglón (mismo que usa el cobro unitario).
concepto: autoConcepto(_findR(f.id)),
}));
try {
const res = await api("/cobrar-lote", {method:"POST", body: JSON.stringify({concepto: loteState.concepto, filas})});
const res = await api("/cobrar-lote", {method:"POST", body: JSON.stringify({filas})});
let msg = `Enviados ${res.enviados}`;
if(res.omitidos_sin_telefono && res.omitidos_sin_telefono.length){
msg += ` · ${res.omitidos_sin_telefono.length} sin número omitidos`;
@@ -1707,8 +1719,14 @@ const _MESES_CORTO = ["ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT
function autoConcepto(r){
const tipo = (r && r.tipo) ? r.tipo.toUpperCase() : "COBRO";
const tipoMap = {RENTA: "RENTA", VR: "VR", EXTRA: "EXTRA"};
const tipoStr = tipoMap[tipo] || tipo;
let tipoStr;
if(tipo === "OTRO" && r && r.etiqueta){
// Cobro personalizado: usa la etiqueta del concepto (ej. TENENCIA).
tipoStr = r.etiqueta.toUpperCase().replace(/\s+/g, "-");
} else {
const tipoMap = {RENTA: "RENTA", VR: "VR", EXTRA: "EXTRA"};
tipoStr = tipoMap[tipo] || tipo;
}
const cliente = (r && r.cliente ? r.cliente : "CLIENTE").split(/\s+/)[0].toUpperCase();
const d = new Date();
return `WK-${tipoStr}-${cliente}-${_MESES_CORTO[d.getMonth()]}${String(d.getFullYear()).slice(-2)}`;