feat(cobranza): intro y concepto del mensaje de cobro configurables
Antes 'Le compartimos los datos para realizar su pago:' y 'Concepto: {concepto}'
estaban hardcodeados. Ahora son plantilla editable (texto_intro, texto_concepto)
con variables {cliente}/{vehiculo}/{monto}/{concepto}/{mes}/{fecha}, como saludo/
despedida y los bloques del cuerpo.
Full-stack aditivo: DEFAULT_PLANTILLA + _armar_mensaje_plantilla (backend/lote) +
PlantillaBody; armarMensajeCobro + editor 'Mensaje' (Introducción/Concepto) +
carga/guardado/preview en cobranza.html. Sin config previa → textos por defecto
(mensaje idéntico a hoy). 121 tests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6300220d1e
commit
2e3eca09fa
4 files changed
+54
-4
No files matched your search
@@ -122,8 +122,10 @@ def _armar_mensaje_plantilla(
|
||||
out = ""
|
||||
if pl.get("saludo"):
|
||||
out += _aplicar_vars(pl["saludo"], variables) + "\n\n"
|
||||
out += "Le compartimos los datos para realizar su pago:\n\n"
|
||||
out += f"Concepto: {concepto}\n"
|
||||
intro = pl.get("texto_intro", "Le compartimos los datos para realizar su pago:")
|
||||
concepto_txt = pl.get("texto_concepto", "Concepto: {concepto}")
|
||||
out += _aplicar_vars(intro, variables) + "\n\n"
|
||||
out += _aplicar_vars(concepto_txt, variables) + "\n"
|
||||
if pl.get("incluir_cliente") is not False and cliente:
|
||||
out += _aplicar_vars(T["cliente"], variables) + "\n"
|
||||
if pl.get("incluir_vehiculo") is not False and vehiculo:
|
||||
@@ -256,6 +258,8 @@ class PlantillaBody(BaseModel):
|
||||
incluir_fecha_limite: bool | None = None
|
||||
incluir_link: bool | None = None
|
||||
# Texto editable de cada bloque del cuerpo.
|
||||
texto_intro: str | None = None
|
||||
texto_concepto: str | None = None
|
||||
texto_cliente: str | None = None
|
||||
texto_vehiculo: str | None = None
|
||||
texto_monto: str | None = None
|
||||
|
||||
@@ -1429,6 +1429,8 @@ DEFAULT_PLANTILLA: dict = {
|
||||
"incluir_link": True,
|
||||
# Texto editable de cada bloque del cuerpo (soporta variables {cliente},
|
||||
# {vehiculo}, {monto}, {fecha}, {concepto}, {mes}).
|
||||
"texto_intro": "Le compartimos los datos para realizar su pago:",
|
||||
"texto_concepto": "Concepto: {concepto}",
|
||||
"texto_cliente": "Cliente: {cliente}",
|
||||
"texto_vehiculo": "Vehículo: {vehiculo}",
|
||||
"texto_monto": "Monto: {monto}",
|
||||
|
||||
@@ -49,6 +49,33 @@ def test_lote_hereda_plantilla():
|
||||
assert out.rstrip().endswith("Gracias, ACME.") # despedida con variable
|
||||
|
||||
|
||||
def test_intro_y_concepto_por_default():
|
||||
# Sin texto_intro/texto_concepto en la plantilla → textos por defecto.
|
||||
out = _armar_mensaje_plantilla(
|
||||
PLANTILLA, CUENTAS,
|
||||
cliente="ACME", vehiculo="HILUX", concepto="WK-RENTA-ACME",
|
||||
monto=100, link="http://x",
|
||||
)
|
||||
assert "Le compartimos los datos para realizar su pago:" in out
|
||||
assert "Concepto: WK-RENTA-ACME" in out
|
||||
|
||||
|
||||
def test_intro_y_concepto_configurables():
|
||||
# texto_intro y texto_concepto personalizados (con variables) se aplican.
|
||||
pl = dict(PLANTILLA,
|
||||
texto_intro="Estimado {cliente}, sus datos de pago:",
|
||||
texto_concepto="Referencia de pago: {concepto}")
|
||||
out = _armar_mensaje_plantilla(
|
||||
pl, CUENTAS,
|
||||
cliente="ACME", vehiculo="HILUX", concepto="WK-RENTA-ACME",
|
||||
monto=100, link="http://x",
|
||||
)
|
||||
assert "Estimado ACME, sus datos de pago:" in out
|
||||
assert "Referencia de pago: WK-RENTA-ACME" in out
|
||||
assert "Le compartimos los datos para realizar su pago:" not in out
|
||||
assert "Concepto: WK-RENTA-ACME" not in out
|
||||
|
||||
|
||||
def test_lote_sin_link_ni_cuentas_avisa():
|
||||
pl = dict(PLANTILLA, incluir_link=False)
|
||||
out = _armar_mensaje_plantilla(
|
||||
|
||||
+19
-2
@@ -412,6 +412,14 @@
|
||||
<textarea class="form-input" id="pl-saludo" rows="2" oninput="renderVistaPreviaMsg()"></textarea>
|
||||
<div class="form-hint">Variables: <code>{cliente}</code> <code>{vehiculo}</code> <code>{monto}</code> <code>{concepto}</code> <code>{mes}</code></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Introducción (antes de los datos)</label>
|
||||
<textarea class="form-input" id="pl-intro" rows="2" oninput="renderVistaPreviaMsg()"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Concepto</label>
|
||||
<input type="text" class="form-input" id="pl-concepto" oninput="renderVistaPreviaMsg()" placeholder="Concepto: {concepto}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Despedida</label>
|
||||
<textarea class="form-input" id="pl-despedida" rows="3" oninput="renderVistaPreviaMsg()"></textarea>
|
||||
@@ -1773,6 +1781,8 @@ function bloqueChanged(){ sincBloquesUI(); renderVistaPreviaMsg(); }
|
||||
function rellenarPlantillaInputs(){
|
||||
const p = (configGlobal && configGlobal.plantilla) ? configGlobal.plantilla : {};
|
||||
document.getElementById("pl-saludo").value = p.saludo || "";
|
||||
document.getElementById("pl-intro").value = p.texto_intro != null ? p.texto_intro : "Le compartimos los datos para realizar su pago:";
|
||||
document.getElementById("pl-concepto").value = p.texto_concepto != null ? p.texto_concepto : "Concepto: {concepto}";
|
||||
document.getElementById("pl-despedida").value = p.despedida || "";
|
||||
document.getElementById("pl-cliente").checked = p.incluir_cliente !== false;
|
||||
document.getElementById("pl-vehiculo").checked = p.incluir_vehiculo !== false;
|
||||
@@ -1790,6 +1800,8 @@ function rellenarPlantillaInputs(){
|
||||
async function guardarPlantilla(){
|
||||
const body = {
|
||||
saludo: document.getElementById("pl-saludo").value,
|
||||
texto_intro: document.getElementById("pl-intro").value,
|
||||
texto_concepto: document.getElementById("pl-concepto").value,
|
||||
despedida: document.getElementById("pl-despedida").value,
|
||||
incluir_cliente: document.getElementById("pl-cliente").checked,
|
||||
incluir_vehiculo: document.getElementById("pl-vehiculo").checked,
|
||||
@@ -1874,10 +1886,13 @@ function armarMensajeCobro(r, monto, concepto, link){
|
||||
};
|
||||
const incluirLink = (pl.incluir_link !== false) && !!link;
|
||||
|
||||
const introTxt = pl.texto_intro != null ? pl.texto_intro : "Le compartimos los datos para realizar su pago:";
|
||||
const conceptoTxt = pl.texto_concepto != null ? pl.texto_concepto : "Concepto: {concepto}";
|
||||
|
||||
let out = "";
|
||||
if(pl.saludo) out += _aplicarVariables(pl.saludo, vars) + "\n\n";
|
||||
out += "Le compartimos los datos para realizar su pago:\n\n";
|
||||
out += `Concepto: ${concepto}\n`;
|
||||
out += _aplicarVariables(introTxt, vars) + "\n\n";
|
||||
out += _aplicarVariables(conceptoTxt, vars) + "\n";
|
||||
if(pl.incluir_cliente !== false && r.cliente) out += _aplicarVariables(T.cliente, vars) + "\n";
|
||||
if(pl.incluir_vehiculo !== false && r.vehiculo) out += _aplicarVariables(T.vehiculo, vars) + "\n";
|
||||
if(pl.incluir_monto !== false) out += _aplicarVariables(T.monto, vars) + "\n";
|
||||
@@ -1915,6 +1930,8 @@ function renderVistaPreviaMsg(){
|
||||
cuentas: (configGlobal && configGlobal.cuentas) ? configGlobal.cuentas : [],
|
||||
plantilla: {
|
||||
saludo: document.getElementById("pl-saludo").value,
|
||||
texto_intro: document.getElementById("pl-intro").value,
|
||||
texto_concepto: document.getElementById("pl-concepto").value,
|
||||
despedida: document.getElementById("pl-despedida").value,
|
||||
incluir_cliente: document.getElementById("pl-cliente").checked,
|
||||
incluir_vehiculo: document.getElementById("pl-vehiculo").checked,
|
||||
|
||||
Reference in new issue
Block a user