diff options
| author | Thibault Delavallée <tde@odoo.com> | 2016-12-06 13:09:07 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2016-12-06 15:15:48 +0100 |
| commit | db72451607383cd8f4c6a674868a9f468ae828ef (patch) | |
| tree | 55c0f62635fdcbb1a05369438c3533dc5b7e4d38 /addons/mail/tests/test_mail_message.py | |
| parent | df037e295971650e8843b2ee668501e7aa3e7df6 (diff) | |
[FIX] mail: avoid notifying a message by email when it is already an email
When creating a mail.mail without giving a mail_message_id, a new mail.message
is created. It does then through _notify that notifies people of the message
creation. This leads to mail being sent two times, one when sending the
mail.mail, one when sending the notification.
This commits fixes that behavior. When creating directly a mail.mail without
giving a mail.message, call to _notify is bypassed. This way either an email
is created, either a message that has to be notified is created, but not both.
Diffstat (limited to 'addons/mail/tests/test_mail_message.py')
| -rw-r--r-- | addons/mail/tests/test_mail_message.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/addons/mail/tests/test_mail_message.py b/addons/mail/tests/test_mail_message.py index fb9da1f7ccb..cc68a1dd8bc 100644 --- a/addons/mail/tests/test_mail_message.py +++ b/addons/mail/tests/test_mail_message.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import itertools + from odoo.addons.mail.tests.common import TestMail from odoo.exceptions import AccessError, except_orm from odoo.tools import mute_logger @@ -111,6 +113,21 @@ class TestMailMessage(TestMail): self.assertNotIn('mail.channel', msg.message_id) self.assertNotIn('-%d-' % self.group_pigs.id, msg.message_id) + def test_mail_message_notify_from_mail_mail(self): + # Due ot post-commit hooks, store send emails in every step + self.email_to_list = [] + mail = self.env['mail.mail'].create({ + 'body_html': '<p>Test</p>', + 'email_to': 'test@example.com', + 'partner_ids': [(4, self.user_employee.partner_id.id)] + }) + self.email_to_list.extend(itertools.chain.from_iterable(sent_email['email_to'] for sent_email in self._mails if sent_email.get('email_to'))) + self.assertNotIn(u'Ernest Employee <e.e@example.com>', self.email_to_list) + mail.send() + self.email_to_list.extend(itertools.chain.from_iterable(sent_email['email_to'] for sent_email in self._mails if sent_email.get('email_to'))) + self.assertNotIn(u'Ernest Employee <e.e@example.com>', self.email_to_list) + self.assertIn(u'test@example.com', self.email_to_list) + @mute_logger('odoo.addons.mail.models.mail_mail') def test_mail_message_access_search(self): # Data: various author_ids, partner_ids, documents |
