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/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 7f7276b6b23..b2ad14ca4c0 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1887,12 +1887,12 @@ class MailThread(models.AbstractModel): # MESSAGE POST TOOLS # ------------------------------------------------------ - def message_post_with_view(self, views_or_xmlid, **kwargs): - """ Helper method to send a mail / post a message using a view_id to - render using the ir.qweb engine. This method is stand alone, because - there is nothing in template and composer that allows to handle - views in batch. This method should probably disappear when templates - handle ir ui views. """ + def _message_compose_with_view(self, views_or_xmlid, message_log=False, **kwargs): + """ Helper method to send a mail / post a message / log a note using + a view_id to render using the ir.qweb engine. This method is stand + alone, because there is nothing in template and composer that allows + to handle views in batch. This method should probably disappear when + templates handle ir ui views. """ values = kwargs.pop('values', None) or dict() try: from odoo.addons.http_routing.models.ir_http import slug @@ -1908,8 +1908,15 @@ class MailThread(models.AbstractModel): for record in self: values['object'] = record rendered_template = views._render(values, engine='ir.qweb', minimal_qcontext=True) - kwargs['body'] = rendered_template - record.message_post_with_template(False, **kwargs) + if message_log: + return record._message_log(body=rendered_template, **kwargs) + else: + kwargs['body'] = rendered_template + return record.message_post_with_template(False, **kwargs) + + def message_post_with_view(self, views_or_xmlid, **kwargs): + """ Helper method to send a mail / post a message using a view_id """ + self._message_compose_with_view(views_or_xmlid, **kwargs) def message_post_with_template(self, template_id, email_layout_xmlid=None, auto_commit=False, **kwargs): """ Helper method to send a mail with a template @@ -1986,6 +1993,10 @@ class MailThread(models.AbstractModel): MailThread._notify_thread(new_message, values, **notif_kwargs) return new_message + def _message_log_with_view(self, views_or_xmlid, **kwargs): + """ Helper method to log a note using a view_id without notifying followers. """ + return self._message_compose_with_view(views_or_xmlid, message_log=True, **kwargs) + def _message_log(self, *, body='', author_id=None, email_from=None, subject=False, message_type='notification', **kwargs): """ Shortcut allowing to post note on a document. It does not perform any notification and pre-computes some values to have a short code diff --git a/addons/test_mail/__manifest__.py b/addons/test_mail/__manifest__.py index 281d3bb0c5a..36f95fa28ae 100644 --- a/addons/test_mail/__manifest__.py +++ b/addons/test_mail/__manifest__.py @@ -14,8 +14,8 @@ tests independently to functional aspects of other models. """, 'security/ir.model.access.csv', 'security/test_mail_security.xml', 'data/data.xml', + 'data/mail_template_data.xml', 'data/subtype_data.xml', - 'data/template_data.xml', ], 'demo': [ ], diff --git a/addons/test_mail/data/template_data.xml b/addons/test_mail/data/mail_template_data.xml similarity index 93% rename from addons/test_mail/data/template_data.xml rename to addons/test_mail/data/mail_template_data.xml index cc307521e7b..2880f359047 100644 --- a/addons/test_mail/data/template_data.xml +++ b/addons/test_mail/data/mail_template_data.xml @@ -33,4 +33,8 @@ + +Hello
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'})