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>
120 lines
4.5 KiB
Python
120 lines
4.5 KiB
Python
"""
|
|
El mensaje del cobro en lote debe heredar la plantilla del panel
|
|
(saludo, textos editables por bloque, cuentas SPEI, link y despedida).
|
|
"""
|
|
import os
|
|
|
|
os.environ.setdefault("OPENAI_API_KEY", "test-key-no-usada")
|
|
|
|
from src.api.cobranza_api import _armar_mensaje_plantilla, _fecha_vencimiento_str
|
|
|
|
|
|
PLANTILLA = {
|
|
"saludo": "Hola {cliente}, le saludamos.",
|
|
"despedida": "Gracias, {cliente}.",
|
|
"incluir_cliente": True,
|
|
"incluir_vehiculo": True,
|
|
"incluir_monto": True,
|
|
"incluir_fecha_limite": False, # se omite a propósito
|
|
"incluir_link": True,
|
|
"texto_cliente": "Cliente: {cliente}",
|
|
"texto_vehiculo": "Unidad: {vehiculo}", # texto editado
|
|
"texto_monto": "Total a pagar: {monto}", # texto editado
|
|
"texto_fecha": "Fecha límite: {fecha}",
|
|
"texto_link": "Pague aquí:", # texto editado
|
|
}
|
|
|
|
CUENTAS = [
|
|
{"id": "1", "banco": "BBVA", "beneficiario": "WK", "cuenta": "123",
|
|
"clabe": "012345678901234567", "incluir_en_mensaje": True},
|
|
{"id": "2", "banco": "OCULTA", "incluir_en_mensaje": False}, # no debe salir
|
|
]
|
|
|
|
|
|
def test_lote_hereda_plantilla():
|
|
out = _armar_mensaje_plantilla(
|
|
PLANTILLA, CUENTAS,
|
|
cliente="ACME", vehiculo="HILUX", concepto="WK-RENTA-ACME",
|
|
monto=1234.5, link="http://pago/x",
|
|
)
|
|
assert "Hola ACME, le saludamos." in out # saludo con variable
|
|
assert "Concepto: WK-RENTA-ACME" in out
|
|
assert "Cliente: ACME" in out
|
|
assert "Unidad: HILUX" in out # texto editado de vehículo
|
|
assert "Total a pagar: $1,234.50" in out # texto editado + formato
|
|
assert "Fecha límite" not in out # bloque desactivado
|
|
assert "🏦 BBVA" in out and "CLABE: 012345678901234567" in out
|
|
assert "OCULTA" not in out # cuenta no incluida
|
|
assert "Pague aquí:" in out and "http://pago/x" in out
|
|
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(
|
|
pl, [], # sin cuentas
|
|
cliente="ACME", vehiculo="HILUX", concepto="X", monto=100, link="",
|
|
)
|
|
assert "No hay cuentas activadas ni link configurado" in out
|
|
assert "http" not in out
|
|
|
|
|
|
def test_fecha_vencimiento_vr_usa_fecha_del_renglon():
|
|
r = {"tipo": "vr", "fecha_vencimiento": "2026-06-30"}
|
|
assert _fecha_vencimiento_str(r) == "30/06/2026"
|
|
|
|
|
|
def test_fecha_vencimiento_renta_usa_dia_pago_mes_actual():
|
|
# renta: día de pago + mes/año en curso (sin sumar días).
|
|
from datetime import datetime
|
|
from src.services.cobranza_acumulada import MEXICO
|
|
ahora = datetime.now(MEXICO)
|
|
r = {"tipo": "renta", "dia_pago": 5}
|
|
esperado = f"05/{ahora.month:02d}/{ahora.year}"
|
|
assert _fecha_vencimiento_str(r) == esperado
|
|
|
|
|
|
def test_fecha_vacia_omite_la_linea():
|
|
pl = dict(PLANTILLA, incluir_fecha_limite=True)
|
|
out = _armar_mensaje_plantilla(
|
|
pl, [], cliente="ACME", vehiculo="HILUX", concepto="X",
|
|
monto=100, link="http://x", fecha="", # sin fecha => sin línea
|
|
)
|
|
assert "Fecha límite" not in out
|
|
|
|
|
|
def test_fecha_se_incluye_cuando_se_pasa():
|
|
pl = dict(PLANTILLA, incluir_fecha_limite=True)
|
|
out = _armar_mensaje_plantilla(
|
|
pl, [], cliente="ACME", vehiculo="HILUX", concepto="X",
|
|
monto=100, link="http://x", fecha="30/06/2026",
|
|
)
|
|
assert "Fecha límite: 30/06/2026" in out
|