mirror of https://github.com/OCA/social.git
[FIX] mail_composer_cc_bcc:send RFQ by email
parent
aab05801f8
commit
81a914c73c
|
@ -34,6 +34,9 @@ class MailThread(models.AbstractModel):
|
|||
message, additional_values=additional_values
|
||||
)
|
||||
context = self.env.context
|
||||
skip_adding_cc_bcc = context.get("skip_adding_cc_bcc", False)
|
||||
if skip_adding_cc_bcc:
|
||||
return res
|
||||
|
||||
partners_cc = context.get("partner_cc_ids", None)
|
||||
if partners_cc:
|
||||
|
@ -55,7 +58,8 @@ class MailThread(models.AbstractModel):
|
|||
rdata = super()._notify_get_recipients(message, msg_vals, **kwargs)
|
||||
context = self.env.context
|
||||
is_from_composer = context.get("is_from_composer", False)
|
||||
if not is_from_composer:
|
||||
skip_adding_cc_bcc = context.get("skip_adding_cc_bcc", False)
|
||||
if not is_from_composer or skip_adding_cc_bcc:
|
||||
return rdata
|
||||
for pdata in rdata:
|
||||
pdata["type"] = "customer"
|
||||
|
@ -100,7 +104,8 @@ class MailThread(models.AbstractModel):
|
|||
message, recipients_data, model_description, msg_vals=msg_vals
|
||||
)
|
||||
is_from_composer = self.env.context.get("is_from_composer", False)
|
||||
if not is_from_composer:
|
||||
skip_adding_cc_bcc = self.env.context.get("skip_adding_cc_bcc", False)
|
||||
if not is_from_composer or skip_adding_cc_bcc:
|
||||
return res
|
||||
ids = []
|
||||
customer_data = None
|
||||
|
@ -116,3 +121,8 @@ class MailThread(models.AbstractModel):
|
|||
else:
|
||||
customer_data["recipients"] += ids
|
||||
return [customer_data]
|
||||
|
||||
def _notify_thread(self, message, msg_vals=False, **kwargs):
|
||||
if message.message_type == "notification":
|
||||
self = self.with_context(skip_adding_cc_bcc=True)
|
||||
return super()._notify_thread(message, msg_vals, **kwargs)
|
||||
|
|
|
@ -4,9 +4,11 @@ import hashlib
|
|||
import inspect
|
||||
|
||||
from odoo import tools
|
||||
from odoo.tests import Form
|
||||
from odoo.tests import Form, tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
from odoo.addons.mail.models.mail_template import MailTemplate as MailTemplate_upstream
|
||||
from odoo.addons.mail.tests.common import MailCase
|
||||
from odoo.addons.mail.tests.test_mail_composer import TestMailComposerForm
|
||||
from odoo.addons.mail.wizard.mail_compose_message import (
|
||||
MailComposer as MailComposer_upstream,
|
||||
|
@ -203,3 +205,81 @@ Test Template<br></p>""",
|
|||
if subject == mail.get("subject"):
|
||||
sent_mails += 1
|
||||
self.assertEqual(sent_mails, 2, "There should be 2 mails sent")
|
||||
|
||||
|
||||
@tagged("-at_install", "post_install")
|
||||
class TestMailComposerCcBccWithTracking(TransactionCase, MailCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.partner = cls.env.ref("base.res_partner_address_31")
|
||||
cls.partner_cc = cls.env.ref("base.partner_demo")
|
||||
cls.partner_bcc = cls.env.ref("base.res_partner_main2")
|
||||
cls.admin_user = cls.env.ref("base.user_admin")
|
||||
|
||||
if "purchase.order" in cls.env:
|
||||
cls.new_po = (
|
||||
cls.env["purchase.order"]
|
||||
.create(
|
||||
{
|
||||
"partner_id": cls.partner.id,
|
||||
}
|
||||
)
|
||||
.with_context(mail_notrack=False)
|
||||
)
|
||||
|
||||
def test_tracking_mail_without_cc_bcc(self):
|
||||
if "purchase.order" in self.env:
|
||||
self.cr.precommit.clear()
|
||||
# create a PO
|
||||
# user subscribe to tracking status of PO
|
||||
self.new_po.message_subscribe(
|
||||
partner_ids=self.admin_user.partner_id.ids,
|
||||
subtype_ids=(
|
||||
(
|
||||
self.env.ref("purchase.mt_rfq_sent")
|
||||
| self.env.ref("purchase.mt_rfq_confirmed")
|
||||
).ids
|
||||
),
|
||||
)
|
||||
|
||||
composer_ctx = self.new_po.action_rfq_send()
|
||||
# send RFQ with cc/bcc
|
||||
form = Form(
|
||||
self.env["mail.compose.message"].with_context(**composer_ctx["context"])
|
||||
)
|
||||
composer = form.save()
|
||||
composer.partner_ids = self.partner
|
||||
composer.partner_cc_ids = self.partner_cc
|
||||
composer.partner_bcc_ids = self.partner_bcc
|
||||
|
||||
with self.mock_mail_gateway(), self.mock_mail_app():
|
||||
composer._action_send_mail()
|
||||
self.flush_tracking()
|
||||
self.assertEqual(
|
||||
len(self._new_msgs),
|
||||
2,
|
||||
"Expected a tracking message and a RFQ message",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.ref("purchase.mt_rfq_sent"),
|
||||
self._new_msgs[1].subtype_id.id,
|
||||
"Expected a tracking message",
|
||||
)
|
||||
|
||||
# RFQ email should include cc/bcc
|
||||
rfq_message = self._new_msgs.filtered(lambda x: x.message_type == "comment")
|
||||
self.assertEqual(len(rfq_message.notified_partner_ids), 3)
|
||||
self.assertEqual(len(rfq_message.notification_ids), 3)
|
||||
rfq_mail = rfq_message.mail_ids
|
||||
self.assertEqual(len(rfq_mail.recipient_ids), 3)
|
||||
|
||||
# tracking email should not include cc/bcc
|
||||
tracking_message = self._new_msgs.filtered(
|
||||
lambda x: x.message_type == "notification"
|
||||
)
|
||||
tracking_field_mail = tracking_message.mail_ids
|
||||
self.assertEqual(len(tracking_field_mail.recipient_ids), 1)
|
||||
self.assertEqual(
|
||||
tracking_field_mail.recipient_ids, self.admin_user.partner_id
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue