From 7c7cb2e8d28572ea8faf3c6d543cfacb04742e9f Mon Sep 17 00:00:00 2001 From: Chafique Date: Mon, 28 Sep 2020 12:06:38 +0200 Subject: [PATCH 1/3] [ADD] mail_single_send_several_recipients module --- .../README.rst | 13 +++++++++ .../__init__.py | 3 ++ .../__manifest__.py | 12 ++++++++ .../models/__init__.py | 3 ++ .../models/mail_mail.py | 28 +++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 mail_single_send_several_recipients/README.rst create mode 100644 mail_single_send_several_recipients/__init__.py create mode 100644 mail_single_send_several_recipients/__manifest__.py create mode 100644 mail_single_send_several_recipients/models/__init__.py create mode 100644 mail_single_send_several_recipients/models/mail_mail.py diff --git a/mail_single_send_several_recipients/README.rst b/mail_single_send_several_recipients/README.rst new file mode 100644 index 00000000..60b184a3 --- /dev/null +++ b/mail_single_send_several_recipients/README.rst @@ -0,0 +1,13 @@ +Mail Single Send with Several Recipients +======================================== + +With this module, when there are several recipients, +Odoo send only one e-mail with all the addressees and no, one email per address. + +Credits +======= + +Contributors +------------ + +* Chafique Delli (chafique.delli@akretion.com) diff --git a/mail_single_send_several_recipients/__init__.py b/mail_single_send_several_recipients/__init__.py new file mode 100644 index 00000000..cde864ba --- /dev/null +++ b/mail_single_send_several_recipients/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/mail_single_send_several_recipients/__manifest__.py b/mail_single_send_several_recipients/__manifest__.py new file mode 100644 index 00000000..6c716772 --- /dev/null +++ b/mail_single_send_several_recipients/__manifest__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Mail Single Send with Several Recipients', + 'version': '10.0.1.0.0', + 'category': 'Mail', + 'license': 'AGPL-3', + 'summary': "When there are several recipients, always send only one e-mail for all the addressees", + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['mail'], + 'installable': True, +} diff --git a/mail_single_send_several_recipients/models/__init__.py b/mail_single_send_several_recipients/models/__init__.py new file mode 100644 index 00000000..4e104e9f --- /dev/null +++ b/mail_single_send_several_recipients/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import mail_mail diff --git a/mail_single_send_several_recipients/models/mail_mail.py b/mail_single_send_several_recipients/models/mail_mail.py new file mode 100644 index 00000000..885a7eb4 --- /dev/null +++ b/mail_single_send_several_recipients/models/mail_mail.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +from odoo import models, api +from email.utils import formataddr + + +class MailMail(models.Model): + _inherit = 'mail.mail' + + @api.multi + def send(self, auto_commit=False, raise_exception=False): + for mail in self: + email_to = [] + for partner in mail.recipient_ids: + for partner_email in [formataddr((partner.name, partner.email))]: + email_to.append(partner_email) + mail.email_to = email_to + return super(MailMail, self).send(auto_commit=auto_commit, + raise_exception=raise_exception) + + @api.multi + def send_get_mail_to(self, partner=None): + self.ensure_one() + email_to = [] + for partner in self.recipient_ids: + email_to.append(formataddr((partner.name, partner.email))) + self.recipient_ids = [(6, 0, [])] + return email_to From 20dcf1a3330e6c82facdb09db8c19dab2bea962a Mon Sep 17 00:00:00 2001 From: Chafique Date: Thu, 1 Oct 2020 18:14:22 +0200 Subject: [PATCH 2/3] [FIX] README.rst --- mail_single_send_several_recipients/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail_single_send_several_recipients/README.rst b/mail_single_send_several_recipients/README.rst index 60b184a3..8129f7c5 100644 --- a/mail_single_send_several_recipients/README.rst +++ b/mail_single_send_several_recipients/README.rst @@ -2,7 +2,7 @@ Mail Single Send with Several Recipients ======================================== With this module, when there are several recipients, -Odoo send only one e-mail with all the addressees and no, one email per address. +Odoo sends only one single e-mail with all the addressees instead of one email per address. Credits ======= From b57485cf7c7862d3aeefd3ff2b227b5e3a2e6aba Mon Sep 17 00:00:00 2001 From: Chafique Date: Fri, 2 Oct 2020 09:58:30 +0200 Subject: [PATCH 3/3] [FIX] call super() method in send_get_mail_to function --- mail_single_send_several_recipients/models/mail_mail.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mail_single_send_several_recipients/models/mail_mail.py b/mail_single_send_several_recipients/models/mail_mail.py index 885a7eb4..fdde4d87 100644 --- a/mail_single_send_several_recipients/models/mail_mail.py +++ b/mail_single_send_several_recipients/models/mail_mail.py @@ -20,6 +20,7 @@ def send(self, auto_commit=False, raise_exception=False): @api.multi def send_get_mail_to(self, partner=None): + super(MailMail, self).send_get_mail_to(partner=partner) self.ensure_one() email_to = [] for partner in self.recipient_ids: