[FIX] mass_mailing_sms: try to render jinja content when using test wizards

Like the mass_mailing app we want to raise an error in case there is a syntax
error with jinja when we test the mailing and if there is at least one record
in the mailing model.

PR odoo/odoo#55696
Task ID-2312442

X-original-commit: 7370d573ae91cf442d045aec2b49332061f6c0ee
This commit is contained in:
Jérémy Hennecart
2020-10-20 12:29:29 +00:00
committed by Thibault Delavallée
parent eafbc90df8
commit 95705a4ef2
@@ -24,9 +24,16 @@ class MassSMSTest(models.TransientModel):
invalid_numbers = [number for number, info in sanitize_res.items() if info['code']]
if invalid_numbers:
raise exceptions.UserError(_('Following numbers are not correctly encoded: %s, example : "+32 495 85 85 77, +33 545 55 55 55"', repr(invalid_numbers)))
record = self.env[self.mailing_id.mailing_model_real].search([], limit=1)
body = self.mailing_id.body_plaintext
if record:
# Returns a proper error if there is a syntax error with jinja
body = self.env['mail.render.mixin']._render_template(body, self.mailing_id.mailing_model_real, record.ids)[record.id]
self.env['sms.api']._send_sms_batch([{
'res_id': 0,
'number': number,
'content': self.mailing_id.body_plaintext,
'content': body,
} for number in sanitized_numbers])
return True