From 3e4205bb207d7bf0e949f3d214feeaad1e1f4f76 Mon Sep 17 00:00:00 2001 From: trisdoan Date: Tue, 5 Nov 2024 11:33:21 +0700 Subject: [PATCH] [FIX] mail_composer_cc_bcc: duplicate email --- mail_composer_cc_bcc/README.rst | 11 +++------- mail_composer_cc_bcc/models/mail_mail.py | 10 +++++++--- mail_composer_cc_bcc/readme/DESCRIPTION.md | 4 ++-- mail_composer_cc_bcc/readme/ROADMAP.md | 2 -- .../static/description/index.html | 20 ++++++------------- .../tests/test_mail_cc_bcc.py | 7 +++++++ 6 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 mail_composer_cc_bcc/readme/ROADMAP.md diff --git a/mail_composer_cc_bcc/README.rst b/mail_composer_cc_bcc/README.rst index 0fe5fa755..107394618 100644 --- a/mail_composer_cc_bcc/README.rst +++ b/mail_composer_cc_bcc/README.rst @@ -35,11 +35,12 @@ confusing for a lot of end users. This module allows to properly separate To:, Cc:, and Bcc: fields in the Mail Composer. +From Odoo 17.0, this module sends one mail per recipient and keeps same +all headers (To, Cc, Bcc) in all emails + Features -------- -- Add Cc and Bcc fields to mail composer form. Send only once to - multiple email addresses. - Add Cc and Bcc fields to company form to use them as default in mail composer form. - Add Bcc field to mail template form. Use Cc and Bcc fields to lookup @@ -87,12 +88,6 @@ corresponding mail composer's fields. .. |image| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_default_cc_bcc.png .. |image1| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_template_cc_bcc.png -Known issues / Roadmap -====================== - -- Extract account customization (account.invoice.send wizard) to a - specific module mail_composer_cc_bcc_account - Bug Tracker =========== diff --git a/mail_composer_cc_bcc/models/mail_mail.py b/mail_composer_cc_bcc/models/mail_mail.py index 7b03d1593..1df9743cb 100644 --- a/mail_composer_cc_bcc/models/mail_mail.py +++ b/mail_composer_cc_bcc/models/mail_mail.py @@ -44,7 +44,7 @@ class MailMail(models.Model): # Collect recipients (RCPT TO) and update all emails # with the same To, Cc headers (to be shown by email client as users expect) - recipients = [] + recipients = set() for m in res: rcpt_to = None if m["email_to"]: @@ -64,7 +64,7 @@ class MailMail(models.Model): rcpt_to = extract_rfc2822_addresses(m["email_cc"][0])[0] if rcpt_to: - recipients.append(rcpt_to) + recipients.add(rcpt_to) m.update( { @@ -74,5 +74,9 @@ class MailMail(models.Model): } ) - self.env.context = {**self.env.context, "recipients": recipients} + self.env.context = {**self.env.context, "recipients": list(recipients)} + + if len(res) > len(recipients): + res.pop() + return res diff --git a/mail_composer_cc_bcc/readme/DESCRIPTION.md b/mail_composer_cc_bcc/readme/DESCRIPTION.md index 2d5cf2a91..b2fa1d3da 100644 --- a/mail_composer_cc_bcc/readme/DESCRIPTION.md +++ b/mail_composer_cc_bcc/readme/DESCRIPTION.md @@ -5,10 +5,10 @@ confusing for a lot of end users. This module allows to properly separate To:, Cc:, and Bcc: fields in the Mail Composer. +From Odoo 17.0, this module sends one mail per recipient and keeps same all headers (To, Cc, Bcc) in all emails + ## Features -- Add Cc and Bcc fields to mail composer form. Send only once to - multiple email addresses. - Add Cc and Bcc fields to company form to use them as default in mail composer form. - Add Bcc field to mail template form. Use Cc and Bcc fields to lookup diff --git a/mail_composer_cc_bcc/readme/ROADMAP.md b/mail_composer_cc_bcc/readme/ROADMAP.md deleted file mode 100644 index 6fdc20cad..000000000 --- a/mail_composer_cc_bcc/readme/ROADMAP.md +++ /dev/null @@ -1,2 +0,0 @@ -- Extract account customization (account.invoice.send wizard) to a - specific module mail_composer_cc_bcc_account diff --git a/mail_composer_cc_bcc/static/description/index.html b/mail_composer_cc_bcc/static/description/index.html index 1d8619f77..3060e82a3 100644 --- a/mail_composer_cc_bcc/static/description/index.html +++ b/mail_composer_cc_bcc/static/description/index.html @@ -375,11 +375,11 @@ default; instead, it only has a unique Recipients fields, which is confusing for a lot of end users.

This module allows to properly separate To:, Cc:, and Bcc: fields in the Mail Composer.

+

From Odoo 17.0, this module sends one mail per recipient and keeps same +all headers (To, Cc, Bcc) in all emails

Features

@@ -423,15 +422,8 @@ corresponding mail composer’s fields.

image1
-
-

Known issues / Roadmap

- -
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -439,7 +431,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

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 4002baa7a..a592d24ce 100644 --- a/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py +++ b/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py @@ -64,6 +64,7 @@ class TestMailCcBcc(TestMailComposerForm): self.assertIn(func_hash, VALID_HASHES.get("mail.composer:_compute_partner_ids")) def test_email_cc_bcc(self): + self.test_record.email = "test@example.com" form = self.open_mail_composer_form() composer = form.save() # Use object to update Many2many fields (form can't do like this) @@ -75,8 +76,14 @@ class TestMailCcBcc(TestMailComposerForm): with self.mock_mail_gateway(): composer._action_send_mail() + self.assertEqual(len(self._mails), 5) + # Verify recipients of mail.message message = self.test_record.message_ids[0] + + # only keep 1 email to avoid clutting db + # but actually send 1 mail per recipients + self.assertEqual(len(message.mail_ids), 1) self.assertEqual(len(message.recipient_cc_ids), 3) self.assertEqual(len(message.recipient_bcc_ids), 1) # Verify notification