From a2e77a8419418f87f70f1799065999bfdf7ae10e Mon Sep 17 00:00:00 2001 From: "Mariska Archielli (ram)" Date: Mon, 28 Sep 2020 08:27:28 +0000 Subject: [PATCH] [FIX] mass_mailing_sms : traceback on create contact list Fix traceback when creating a new contact by checking the id list is not empty. Task ID : 2302578 closes odoo/odoo#58681 X-original-commit: 31f2bb5e494965d31f5e49d47908fd4b5eb64077 Signed-off-by: Thibault Delavallee (tde) --- addons/mass_mailing/models/mailing_list.py | 39 ++++++++++--------- .../mass_mailing_sms/models/mailing_list.py | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/addons/mass_mailing/models/mailing_list.py b/addons/mass_mailing/models/mailing_list.py index f019721894f..1ce47c83b59 100644 --- a/addons/mass_mailing/models/mailing_list.py +++ b/addons/mass_mailing/models/mailing_list.py @@ -24,24 +24,27 @@ class MassMailingList(models.Model): # Compute number of contacts non opt-out, non blacklisted and valid email recipient for a mailing list def _compute_contact_nbr(self): - self.env.cr.execute(''' - select - list_id, count(*) - from - mailing_contact_list_rel r - left join mailing_contact c on (r.contact_id=c.id) - left join mail_blacklist bl on c.email_normalized = bl.email and bl.active - where - list_id in %s - AND COALESCE(r.opt_out,FALSE) = FALSE - AND c.email_normalized IS NOT NULL - AND bl.id IS NULL - group by - list_id - ''', (tuple(self.ids), )) - data = dict(self.env.cr.fetchall()) - for mailing_list in self: - mailing_list.contact_nbr = data.get(mailing_list.id, 0) + if self.ids: + self.env.cr.execute(''' + select + list_id, count(*) + from + mailing_contact_list_rel r + left join mailing_contact c on (r.contact_id=c.id) + left join mail_blacklist bl on c.email_normalized = bl.email and bl.active + where + list_id in %s + AND COALESCE(r.opt_out,FALSE) = FALSE + AND c.email_normalized IS NOT NULL + AND bl.id IS NULL + group by + list_id + ''', (tuple(self.ids), )) + data = dict(self.env.cr.fetchall()) + for mailing_list in self: + mailing_list.contact_nbr = data.get(mailing_list.id, 0) + else: + self.contact_nbr = 0 def write(self, vals): # Prevent archiving used mailing list diff --git a/addons/mass_mailing_sms/models/mailing_list.py b/addons/mass_mailing_sms/models/mailing_list.py index 86b27e81566..9e48fa7d7bf 100644 --- a/addons/mass_mailing_sms/models/mailing_list.py +++ b/addons/mass_mailing_sms/models/mailing_list.py @@ -8,7 +8,7 @@ class MailingList(models.Model): _inherit = 'mailing.list' def _compute_contact_nbr(self): - if self.env.context.get('mailing_sms'): + if self.env.context.get('mailing_sms') and self.ids: self.env.cr.execute(''' select list_id, count(*) from mailing_contact_list_rel r