diff --git a/src/api/cobranza_api.py b/src/api/cobranza_api.py index b497fe8..8a100a8 100644 --- a/src/api/cobranza_api.py +++ b/src/api/cobranza_api.py @@ -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 diff --git a/src/services/cobranza_acumulada.py b/src/services/cobranza_acumulada.py index 12c8d2c..a3fe7ce 100644 --- a/src/services/cobranza_acumulada.py +++ b/src/services/cobranza_acumulada.py @@ -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}", diff --git a/tests/test_lote_mensaje.py b/tests/test_lote_mensaje.py index 4d6ed75..d058663 100644 --- a/tests/test_lote_mensaje.py +++ b/tests/test_lote_mensaje.py @@ -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( diff --git a/web/cobranza.html b/web/cobranza.html index 9c6e35a..00a80a4 100644 --- a/web/cobranza.html +++ b/web/cobranza.html @@ -412,6 +412,14 @@
Variables: {cliente} {vehiculo} {monto} {concepto} {mes}
+
+ + +
+
+ + +
@@ -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,