diff options
| author | Thibault Delavallée <tde@odoo.com> | 2018-01-26 10:25:50 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2018-01-30 17:20:45 +0100 |
| commit | 8ddca6f95a52d36c4a8731dcf93413e8206dce81 (patch) | |
| tree | 46873f17204f29325fabab5be9efaba62bfe1691 /addons/test_mail/tests/test_message_compose.py | |
| parent | 139737dbeb7369bbc7a923f0c46d88eeddfeac30 (diff) | |
[IMP] mail: introduce _message_log as shortcut when logging notifications
This commit introduces _message_log to use when logging notification-based
notes on a document. Its main purpose is to provide a shortcut to the
complex mechanism of message_post. As it is a lighter code and as it
performs less checks and value computation it allows to clearly gain
queries when logging notes.
It does
* skip the notification process completely. Side effect is that followers
following note subtype are not notified of document created and pure
note tracking. This is considered more as a fix than a feature change.
Indeed following notes means that followers want to receive notes
logged by other users. The fact that system notifications without a
specific subtypes are also notes is a side-effect of the current
implementation;
* support only notification-based notes and should not be used currently
when logging real notes as those could trigger the notification
process;
* skip access rights checks as it creates the message as superuser. It
is therefore defined as a private method and should be called within
a method where access rights are already granted;
On community runbot installing all 203 modules takes 580K queries instead
of 690 at the time of testing. It is a 15% performance increase based on
the 'all modules installation' metric.
In a distant future message_post and message_log could be merged after
some cleaning but it is easier currently to have this shortcut available.
Moreover as there are clouds on the mail module some developers prefer
to already have some optimization and code cleaning done to avoid
loosing all their hair.
This commit includes a small test. In a same distant future more tests
will probably be added depending on how mail API evolves.
Diffstat (limited to 'addons/test_mail/tests/test_message_compose.py')
| -rw-r--r-- | addons/test_mail/tests/test_message_compose.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_message_compose.py b/addons/test_mail/tests/test_message_compose.py index 6c561bab89d..e2668cdac45 100644 --- a/addons/test_mail/tests/test_message_compose.py +++ b/addons/test_mail/tests/test_message_compose.py @@ -3,6 +3,7 @@ import base64 +from email.utils import formataddr from unittest.mock import patch from odoo.addons.test_mail.tests.common import BaseFunctionalTest, MockEmails, TestRecipients @@ -200,6 +201,17 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients): self.assertEqual(reply.needaction_partner_ids, self.user_employee.partner_id) self.assertEqual(reply.parent_id, msg) + def test_post_log(self): + new_note = self.test_record.sudo(self.user_employee)._message_log( + body='<p>Labrador</p>', + ) + + self.assertEqual(new_note.subtype_id, self.env.ref('mail.mt_note')) + self.assertEqual(new_note.body, '<p>Labrador</p>') + 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.needaction_partner_ids, self.env['res.partner']) + class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients): |
