Skip to content

Commit

Permalink
[UPD] mail_composer_cc_bcc: Updated latest version from OCA and fixed…
Browse files Browse the repository at this point in the history
… test scripts
ByteMeAsap committed Dec 19, 2024
1 parent fdfd5a6 commit 4dd2a75
Showing 7 changed files with 47 additions and 28 deletions.
3 changes: 2 additions & 1 deletion mail_composer_cc_bcc/README.rst
Original file line number Diff line number Diff line change
@@ -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 <hailn@trobz.com>
* Son Ho <sonhd@trobz.com>
* Tris Doan <tridm@trobz.com>

* `Therp BV <https://therp.nl>`_:

2 changes: 1 addition & 1 deletion mail_composer_cc_bcc/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
25 changes: 17 additions & 8 deletions mail_composer_cc_bcc/models/mail_mail.py
Original file line number Diff line number Diff line change
@@ -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"),
6 changes: 1 addition & 5 deletions mail_composer_cc_bcc/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions mail_composer_cc_bcc/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

* Hai N. Le <hailn@trobz.com>
* Son Ho <sonhd@trobz.com>
* Tris Doan <tridm@trobz.com>

* `Therp BV <https://therp.nl>`_:

3 changes: 2 additions & 1 deletion mail_composer_cc_bcc/static/description/index.html
Original file line number Diff line number Diff line change
@@ -367,7 +367,7 @@ <h1 class="title">Email CC and BCC</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a692e52c6dc8f5ffa62ea427f03cd81d16de695816840688057506b5fbc873a0
!! source digest: sha256:0f335d8faf739018174065b07692a722b9c890c5624320c54d56e93ce00ce6e7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/16.0/mail_composer_cc_bcc"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_composer_cc_bcc"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Odoo native does not support defining a Cc field in the Mail Composer
@@ -452,6 +452,7 @@ <h1>Contributors</h1>
<ul class="simple">
<li>Hai N. Le &lt;<a class="reference external" href="mailto:hailn&#64;trobz.com">hailn&#64;trobz.com</a>&gt;</li>
<li>Son Ho &lt;<a class="reference external" href="mailto:sonhd&#64;trobz.com">sonhd&#64;trobz.com</a>&gt;</li>
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul>
</blockquote>
</li>
35 changes: 23 additions & 12 deletions mail_composer_cc_bcc/tests/test_mail_cc_bcc.py
Original file line number Diff line number Diff line change
@@ -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,35 +96,35 @@ 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": """<p style="margin:0px 0 12px 0;box-sizing:border-box;">
Test Template<br></p>""",
New Contact<br></p>""",
"email_cc": tools.formataddr(
(partner_cc.name or "False", partner_cc.email or "False")
),
"email_bcc": tools.formataddr(
(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)

0 comments on commit 4dd2a75

Please sign in to comment.