From 0ea27f430c27716e9f995523f050ba70fa4befde Mon Sep 17 00:00:00 2001 From: David Beguin Date: Thu, 15 Apr 2021 09:11:14 +0000 Subject: [PATCH] [IMP] mail: add message_log with view helper This commit allows to log a note and bypass notification process using a template. The method _message_log_with_view has been added. This method render the template using the given view and values (in kwargs) to make the body before calling _message_log(). This process is done by the intermediary method _message_compose_with_view that is now common to message_post_with_view and _message_log_with_view has it follows the same template preparation process. Task ID: 2459416 Linked ENT PR: odoo/enterprise#17553 --- addons/mail/data/mail_templates.xml | 3 ++- addons/mail/models/mail_thread.py | 27 +++++++++++++------ addons/test_mail/__manifest__.py | 2 +- ...mplate_data.xml => mail_template_data.xml} | 4 +++ addons/test_mail/tests/test_message_post.py | 11 ++++++++ 5 files changed, 37 insertions(+), 10 deletions(-) rename addons/test_mail/data/{template_data.xml => mail_template_data.xml} (93%) diff --git a/addons/mail/data/mail_templates.xml b/addons/mail/data/mail_templates.xml index 007417bf72b..2f99061e7cd 100644 --- a/addons/mail/data/mail_templates.xml +++ b/addons/mail/data/mail_templates.xml @@ -351,7 +351,8 @@ Moderate Messages


-

Thank you! +

Thank you!

+ + + diff --git a/addons/test_mail/tests/test_message_post.py b/addons/test_mail/tests/test_message_post.py index c696fb0a263..6ef40ab3c09 100644 --- a/addons/test_mail/tests/test_message_post.py +++ b/addons/test_mail/tests/test_message_post.py @@ -280,6 +280,17 @@ class TestMessagePost(TestMailCommon, TestRecipients): self.assertEqual(new_note.email_from, formataddr((self.user_employee.name, self.user_employee.email))) self.assertEqual(new_note.notified_partner_ids, self.env['res.partner']) + def test_post_log_with_view(self): + new_note = self.test_record.with_user(self.user_employee)._message_log_with_view( + 'test_mail.mail_template_simple_test', values={'partner': self.user_employee.partner_id} + ) + + self.assertEqual(new_note.subtype_id, self.env.ref('mail.mt_note')) + self.assertTrue('

Hello %s,

' % self.user_employee.name in new_note.body) + self.assertEqual(new_note.author_id, self.user_employee.partner_id) + self.assertEqual(new_note.email_from, formataddr((self.user_employee.name, self.user_employee.email))) + self.assertEqual(new_note.notified_partner_ids, self.env['res.partner']) + @mute_logger('odoo.addons.mail.models.mail_mail') def test_post_notify(self): self.user_employee.write({'notification_type': 'inbox'})