From 95705a4ef2994f8e7b8e64412c76a9f00eeafcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Hennecart?= Date: Tue, 11 Aug 2020 11:23:42 +0000 Subject: [PATCH] [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 --- addons/mass_mailing_sms/wizard/mailing_sms_test.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/mass_mailing_sms/wizard/mailing_sms_test.py b/addons/mass_mailing_sms/wizard/mailing_sms_test.py index 198304dc2c6..1ea9f8718eb 100644 --- a/addons/mass_mailing_sms/wizard/mailing_sms_test.py +++ b/addons/mass_mailing_sms/wizard/mailing_sms_test.py @@ -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