[FIX] mail_composer_cc_bcc: duplicate email

pull/1494/head
trisdoan 2024-11-05 11:33:21 +07:00
parent 81a914c73c
commit 3e4205bb20
6 changed files with 25 additions and 29 deletions

View File

@ -35,11 +35,12 @@ confusing for a lot of end users.
This module allows to properly separate To:, Cc:, and Bcc: fields in the This module allows to properly separate To:, Cc:, and Bcc: fields in the
Mail Composer. 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 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 - Add Cc and Bcc fields to company form to use them as default in mail
composer form. composer form.
- Add Bcc field to mail template form. Use Cc and Bcc fields to lookup - 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 .. |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 .. |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 Bug Tracker
=========== ===========

View File

@ -44,7 +44,7 @@ class MailMail(models.Model):
# Collect recipients (RCPT TO) and update all emails # Collect recipients (RCPT TO) and update all emails
# with the same To, Cc headers (to be shown by email client as users expect) # with the same To, Cc headers (to be shown by email client as users expect)
recipients = [] recipients = set()
for m in res: for m in res:
rcpt_to = None rcpt_to = None
if m["email_to"]: if m["email_to"]:
@ -64,7 +64,7 @@ class MailMail(models.Model):
rcpt_to = extract_rfc2822_addresses(m["email_cc"][0])[0] rcpt_to = extract_rfc2822_addresses(m["email_cc"][0])[0]
if rcpt_to: if rcpt_to:
recipients.append(rcpt_to) recipients.add(rcpt_to)
m.update( 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 return res

View File

@ -5,10 +5,10 @@ confusing for a lot of end users.
This module allows to properly separate To:, Cc:, and Bcc: fields in the This module allows to properly separate To:, Cc:, and Bcc: fields in the
Mail Composer. 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 ## 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 - Add Cc and Bcc fields to company form to use them as default in mail
composer form. composer form.
- Add Bcc field to mail template form. Use Cc and Bcc fields to lookup - Add Bcc field to mail template form. Use Cc and Bcc fields to lookup

View File

@ -1,2 +0,0 @@
- Extract account customization (account.invoice.send wizard) to a
specific module mail_composer_cc_bcc_account

View File

@ -375,11 +375,11 @@ default; instead, it only has a unique Recipients fields, which is
confusing for a lot of end users.</p> confusing for a lot of end users.</p>
<p>This module allows to properly separate To:, Cc:, and Bcc: fields in the <p>This module allows to properly separate To:, Cc:, and Bcc: fields in the
Mail Composer.</p> Mail Composer.</p>
<p>From Odoo 17.0, this module sends one mail per recipient and keeps same
all headers (To, Cc, Bcc) in all emails</p>
<div class="section" id="features"> <div class="section" id="features">
<h1>Features</h1> <h1>Features</h1>
<ul class="simple"> <ul class="simple">
<li>Add Cc and Bcc fields to mail composer form. Send only once to
multiple email addresses.</li>
<li>Add Cc and Bcc fields to company form to use them as default in mail <li>Add Cc and Bcc fields to company form to use them as default in mail
composer form.</li> composer form.</li>
<li>Add Bcc field to mail template form. Use Cc and Bcc fields to lookup <li>Add Bcc field to mail template form. Use Cc and Bcc fields to lookup
@ -397,9 +397,8 @@ Only for development or testing purpose, do not use in production.
<ul class="simple"> <ul class="simple">
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li> <li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li> <li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-3">Known issues / Roadmap</a></li> <li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li> <li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a></li>
</ul> </ul>
</div> </div>
<div class="section" id="configuration"> <div class="section" id="configuration">
@ -423,15 +422,8 @@ corresponding mail composers fields.</p>
<blockquote> <blockquote>
<img alt="image1" src="https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_template_cc_bcc.png" /></blockquote> <img alt="image1" src="https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_template_cc_bcc.png" /></blockquote>
</div> </div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h2>
<ul class="simple">
<li>Extract account customization (account.invoice.send wizard) to a
specific module mail_composer_cc_bcc_account</li>
</ul>
</div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2> <h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 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
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2> <h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
</div> </div>
</div> </div>
<div class="section" id="authors"> <div class="section" id="authors">

View File

@ -64,6 +64,7 @@ class TestMailCcBcc(TestMailComposerForm):
self.assertIn(func_hash, VALID_HASHES.get("mail.composer:_compute_partner_ids")) self.assertIn(func_hash, VALID_HASHES.get("mail.composer:_compute_partner_ids"))
def test_email_cc_bcc(self): def test_email_cc_bcc(self):
self.test_record.email = "test@example.com"
form = self.open_mail_composer_form() form = self.open_mail_composer_form()
composer = form.save() composer = form.save()
# Use object to update Many2many fields (form can't do like this) # Use object to update Many2many fields (form can't do like this)
@ -75,8 +76,14 @@ class TestMailCcBcc(TestMailComposerForm):
with self.mock_mail_gateway(): with self.mock_mail_gateway():
composer._action_send_mail() composer._action_send_mail()
self.assertEqual(len(self._mails), 5)
# Verify recipients of mail.message # Verify recipients of mail.message
message = self.test_record.message_ids[0] 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_cc_ids), 3)
self.assertEqual(len(message.recipient_bcc_ids), 1) self.assertEqual(len(message.recipient_bcc_ids), 1)
# Verify notification # Verify notification