From 4dd2a752811a7302bab1d3089d47f0115c3aaca8 Mon Sep 17 00:00:00 2001 From: Anjeel Haria Date: Thu, 19 Dec 2024 16:21:12 +0530 Subject: [PATCH] [UPD] mail_composer_cc_bcc: Updated latest version from OCA and fixed test scripts --- mail_composer_cc_bcc/README.rst | 3 +- mail_composer_cc_bcc/__manifest__.py | 2 +- mail_composer_cc_bcc/models/mail_mail.py | 25 ++++++++----- mail_composer_cc_bcc/models/mail_thread.py | 6 +--- mail_composer_cc_bcc/readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 3 +- .../tests/test_mail_cc_bcc.py | 35 ++++++++++++------- 7 files changed, 47 insertions(+), 28 deletions(-) diff --git a/mail_composer_cc_bcc/README.rst b/mail_composer_cc_bcc/README.rst index c55ba2d3..08c32802 100644 --- a/mail_composer_cc_bcc/README.rst +++ b/mail_composer_cc_bcc/README.rst @@ -7,7 +7,7 @@ Email CC and BCC !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:a692e52c6dc8f5ffa62ea427f03cd81d16de695816840688057506b5fbc873a0 + !! source digest: sha256:0f335d8faf739018174065b07692a722b9c890c5624320c54d56e93ce00ce6e7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png @@ -106,6 +106,7 @@ Contributors * Hai N. Le * Son Ho + * Tris Doan * `Therp BV `_: diff --git a/mail_composer_cc_bcc/__manifest__.py b/mail_composer_cc_bcc/__manifest__.py index 6b6b0185..39edb66f 100644 --- a/mail_composer_cc_bcc/__manifest__.py +++ b/mail_composer_cc_bcc/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Email CC and BCC", "summary": "This module enables sending mail to CC and BCC partners in mail composer form.", - "version": "16.0.2.0.1", + "version": "16.0.2.0.3", "development_status": "Alpha", "category": "Social", "website": "https://github.com/OCA/social", diff --git a/mail_composer_cc_bcc/models/mail_mail.py b/mail_composer_cc_bcc/models/mail_mail.py index 970aae8d..29ab4d6e 100644 --- a/mail_composer_cc_bcc/models/mail_mail.py +++ b/mail_composer_cc_bcc/models/mail_mail.py @@ -18,7 +18,13 @@ def format_emails(partners): emails = [ - tools.formataddr((p.name or "False", p.email or "False")) for p in partners + tools.formataddr( + ( + p.name or "False", + p.email and tools.mail._normalize_email(p.email) or "False", + ) + ) + for p in partners ] return ", ".join(emails) @@ -48,8 +54,8 @@ def _send( # noqa: max-complexity: 4 success_pids = [] failure_type = None # ===== Same with native Odoo ===== - # https://github.com/odoo/odoo/blob/d492bbde35d2b52e975ca252588f5529f07027aa - # /addons/mail/models/mail_mail.py#L461 + # https://github.com/odoo/odoo/blob/55c165dc8777514afa4f1476b82ef6b50b8a7651 + # /addons/mail/models/mail_mail.py#L463 try: if mail.state != "outgoing": if mail.state != "exception" and mail.auto_delete: @@ -75,7 +81,7 @@ def _send( # noqa: max-complexity: 4 email = mail._send_prepare_values() # ===== Same with native Odoo ===== # headers - headers = {} + headers = {"X-Odoo-Message-Id": mail.message_id} bounce_alias = ICP.get_param("mail.bounce.alias") catchall_domain = ICP.get_param("mail.catchall.domain") if bounce_alias and catchall_domain: @@ -129,7 +135,7 @@ def _send( # noqa: max-complexity: 4 ) # protect against ill-formatted email_from when formataddr was used on an already formatted email # noqa: B950 - emails_from = tools.email_split_and_format(mail.email_from) + emails_from = tools.email_split_and_format_normalize(mail.email_from) email_from = emails_from[0] if emails_from else mail.email_from # build an RFC2822 email.message.Message object and send it without queuing @@ -153,7 +159,10 @@ def _send( # noqa: max-complexity: 4 headers=email_headers, ) try: - res = IrMailServer.send_email( + email_to_normalized = email.pop("email_to_normalized", []) + res = IrMailServer.with_context( + send_validated_to=email_to_normalized + ).send_email( msg, mail_server_id=mail.mail_server_id.id, smtp_session=smtp_session, @@ -250,8 +259,8 @@ def build_email(self, email, attachments=None, headers=None): email_from = email.get("email_from") IrMailServer = env["ir.mail_server"] # ===== Same with native Odoo ===== - # https://github.com/odoo/odoo/blob/d492bbde35d2b52e975ca252588f5529f07027aa - # /addons/mail/models/mail_mail.py#L543 + # https://github.com/odoo/odoo/blob/1098b033b4e1811d6ff4b8c3b90aa6b9e697cb93 + # /addons/mail/models/mail_mail.py#L550 msg = IrMailServer.build_email( email_from=email_from, email_to=email.get("email_to"), diff --git a/mail_composer_cc_bcc/models/mail_thread.py b/mail_composer_cc_bcc/models/mail_thread.py index 964987ac..43bf5dd5 100644 --- a/mail_composer_cc_bcc/models/mail_thread.py +++ b/mail_composer_cc_bcc/models/mail_thread.py @@ -62,13 +62,9 @@ def _notify_get_recipients(self, message, msg_vals, **kwargs): recipients_cc_bcc = MailFollowers._get_recipient_data( None, message_type, subtype_id, partners_cc_bcc.ids ) - partners_already_marked_as_recipient = [r.get("id", False) for r in rdata] for _, value in recipients_cc_bcc.items(): for _, data in value.items(): - if ( - not data.get("id") - or data.get("id") in partners_already_marked_as_recipient - ): + if not data.get("id"): continue if not data.get( "notif" diff --git a/mail_composer_cc_bcc/readme/CONTRIBUTORS.rst b/mail_composer_cc_bcc/readme/CONTRIBUTORS.rst index 707d8e42..bd3e5b1b 100644 --- a/mail_composer_cc_bcc/readme/CONTRIBUTORS.rst +++ b/mail_composer_cc_bcc/readme/CONTRIBUTORS.rst @@ -2,6 +2,7 @@ * Hai N. Le * Son Ho + * Tris Doan * `Therp BV `_: diff --git a/mail_composer_cc_bcc/static/description/index.html b/mail_composer_cc_bcc/static/description/index.html index 843e3499..5cdfcf5b 100644 --- a/mail_composer_cc_bcc/static/description/index.html +++ b/mail_composer_cc_bcc/static/description/index.html @@ -367,7 +367,7 @@

Email CC and BCC

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:a692e52c6dc8f5ffa62ea427f03cd81d16de695816840688057506b5fbc873a0 +!! source digest: sha256:0f335d8faf739018174065b07692a722b9c890c5624320c54d56e93ce00ce6e7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Alpha License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

Odoo native does not support defining a Cc field in the Mail Composer @@ -452,6 +452,7 @@

Contributors

diff --git a/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py b/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py index aa24c51b..5480bbb2 100644 --- a/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py +++ b/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py @@ -10,7 +10,13 @@ from odoo.addons.mail.models.mail_mail import MailMail as upstream from odoo.addons.mail.tests.test_mail_composer import TestMailComposer -VALID_HASHES = ["d52cb36b88b33abc9556f7be6718d93f", "461467cd5b356072fc054468c75f6e26"] +VALID_HASHES = [ + "d52cb36b88b33abc9556f7be6718d93f", + "461467cd5b356072fc054468c75f6e26", + "5d1ab352416f5074e131f35f20098d5b", + "46172c91183f2cb50b22a6b3b5e3869b", + "8f26c4084cc7fc300e64d19ccdc944fe", +] class TestMailCcBcc(TestMailComposer): @@ -42,7 +48,12 @@ def test_upstream_file_hash(self): """Test that copied upstream function hasn't received fixes""" func = inspect.getsource(upstream._send).encode() func_hash = hashlib.md5(func).hexdigest() - self.assertIn(func_hash, VALID_HASHES) + self.assertIn( + func_hash, + VALID_HASHES, + "mail.mail#_send has changed in upstream, " + "please adapt the override and add the new hash above", + ) def test_email_cc_bcc(self): form = self.open_mail_composer_form() @@ -85,16 +96,16 @@ def test_template_cc_bcc(self): # Company default values env.company.default_partner_cc_ids = self.partner_cc3 env.company.default_partner_bcc_ids = self.partner_cc2 - # Product template values - tmpl_model = env["ir.model"].search([("model", "=", "product.template")]) + # Res Partner values + res_partner_model = env["ir.model"].search([("model", "=", "res.partner")]) partner_cc = self.partner_cc partner_bcc = self.partner_bcc vals = { - "name": "Product Template: Re: [E-COM11] Cabinet with Doors", - "model_id": tmpl_model.id, - "subject": "Re: [E-COM11] Cabinet with Doors", + "name": "Contact: New Contact", + "model_id": res_partner_model.id, + "subject": "Re: New Contact", "body_html": """

-Test Template

""", + New Contact

""", "email_cc": tools.formataddr( (partner_cc.name or "False", partner_cc.email or "False") ), @@ -102,18 +113,18 @@ def test_template_cc_bcc(self): (partner_bcc.name or "False", partner_bcc.email or "False") ), } - prod_tmpl = env["mail.template"].create(vals) + mail_tmpl = env["mail.template"].create(vals) # Open mail composer form and check for default values from company form = self.open_mail_composer_form() composer = form.save() self.assertEqual(composer.partner_cc_ids, self.partner_cc3) self.assertEqual(composer.partner_bcc_ids, self.partner_cc2) # Change email template and check for values from it - form.template_id = prod_tmpl + form.template_id = mail_tmpl composer = form.save() # Beside existing Cc and Bcc, add template's ones form = Form(composer) - form.template_id = prod_tmpl + form.template_id = mail_tmpl composer = form.save() expecting = self.partner_cc3 + self.partner_cc self.assertEqual(composer.partner_cc_ids, expecting) @@ -128,7 +139,7 @@ def test_template_cc_bcc(self): form.template_id = env["mail.template"] form.save() self.assertFalse(form.template_id) - form.template_id = prod_tmpl + form.template_id = mail_tmpl composer = form.save() expecting = self.partner_cc3 + self.partner_cc self.assertEqual(composer.partner_cc_ids, expecting)