From 4184143193092fcb7850a3b408f2312c8ff4da04 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 0fe5fa75..10739461 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 7b03d159..1df9743c 100644
--- a/mail_composer_cc_bcc/models/mail_mail.py
+++ b/mail_composer_cc_bcc/models/mail_mail.py
@@ -44,7 +44,7 @@ def _prepare_outgoing_list(self, recipients_follower_status=None):
# 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 @@ def _prepare_outgoing_list(self, recipients_follower_status=None):
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 @@ def _prepare_outgoing_list(self, recipients_follower_status=None):
}
)
- 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 2d5cf2a9..b2fa1d3d 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 6fdc20ca..00000000
--- 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 1d8619f7..3060e82a 100644
--- a/mail_composer_cc_bcc/static/description/index.html
+++ b/mail_composer_cc_bcc/static/description/index.html
@@ -375,11 +375,11 @@ Email CC and BCC
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
@@ -397,9 +397,8 @@
Features
@@ -423,15 +422,8 @@
-
-
-
-- Extract account customization (account.invoice.send wizard) to a
-specific module mail_composer_cc_bcc_account
-
-
-
+
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 @@
Do not contact contributors directly about support or help with technical issues.
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 4002baa7..a592d24c 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 @@ def test_MailComposer_upstream_file_hash(self):
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 @@ def test_email_cc_bcc(self):
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