From a3befcc5a970d17aa01e07bee477e615923cd5f9 Mon Sep 17 00:00:00 2001 From: "Eteil Djoumatchoua(etdj) etdj@odoo.com" Date: Tue, 21 Nov 2023 11:13:42 +0100 Subject: [PATCH] [FIX] mail: set body on mail.message on event registration confirmation Steps: - Go to any event with tickets and using the ticket confirmation template, sending 'after new confirmation'. - Confirm a new attendee. - An email is sent but the chatter only shows the attachment and the subject, with no body. Issue: Chatter should show full content of the email. Reason: Above 16.2+ the 'body' is not implicitely set when genrating the template in ``mail_template.send_mail()``. As discussed with RETH, when requesting the 'body_html' for a template, setting the 'body' solves the problem. opw-3562438 closes odoo/odoo#151930 X-original-commit: 0a3d4b10a7c81d05d9bf6864b0b9a2f48f09b2a0 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_template.py | 2 ++ addons/test_mail/tests/test_mail_template.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 3eff2c4bee2..5fe5f992bb3 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -652,6 +652,8 @@ class MailTemplate(models.Model): ) values['body_html'] = self.env['mail.render.mixin']._replace_local_links(body) + if 'body_html' in values: + values['body'] = values['body_html'] mail = self.env['mail.mail'].sudo().create(values) diff --git a/addons/test_mail/tests/test_mail_template.py b/addons/test_mail/tests/test_mail_template.py index 3ee49919545..5acd3ce20d6 100644 --- a/addons/test_mail/tests/test_mail_template.py +++ b/addons/test_mail/tests/test_mail_template.py @@ -105,6 +105,16 @@ class TestMailTemplate(TestMailTemplateCommon): self.assertFalse(mail.scheduled_date) self.assertEqual(mail.state, 'outgoing') + @mute_logger('odoo.addons.mail.models.mail_mail') + def test_template_send_mail_body(self): + """ Test that the body and body_html is set correctly in 'mail.mail' + when sending an email from mail.template """ + mail_id = self.test_template.send_mail(self.test_record.id) + mail = self.env['mail.mail'].sudo().browse(mail_id) + body_result = '

EnglishBody for %s

' % self.test_record.name + + self.assertEqual(mail.body_html, body_result) + self.assertEqual(mail.body, body_result) @tagged('mail_template', 'multi_lang') class TestMailTemplateLanguages(TestMailTemplateCommon):