diff options
| author | Mariska Archielli (ram) <ram@odoo.com> | 2020-09-28 08:27:28 +0000 |
|---|---|---|
| committer | Mariska Archielli (ram) <ram@odoo.com> | 2020-09-28 09:59:55 +0000 |
| commit | 31f2bb5e494965d31f5e49d47908fd4b5eb64077 (patch) | |
| tree | ea394e518e72d259b5b44881aa5ec413cacf017e | |
| parent | e6c93c2632555b100d31ba6745a8bca62d44450e (diff) | |
[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#58555
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
| -rw-r--r-- | addons/mass_mailing/models/mailing_list.py | 39 | ||||
| -rw-r--r-- | addons/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 |
