[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) <tde@openerp.com>
This commit is contained in:
Mariska Archielli (ram)
2020-09-28 13:16:07 +00:00
parent 1cfd35cc97
commit a2e77a8419
2 changed files with 22 additions and 19 deletions
+21 -18
View File
@@ -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
@@ -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