[FW][FIX] mass_mailing: check fields for seen list are stored before going into SQL
Seen list (aka already mailed records) computation is done in SQL to speedup computation. It is based on an heuristic to find fields to check (either a partner, either an email). However it checks fields are present in model but does not check they are stored. This leads to traceback if fields are not stored. Task-2852943 X-original-commit: fa11070d4533475778ea933225e30d06a09406bc Part-of: odoo/odoo#94532
This commit is contained in:
committed by
Thibault Delavallée
parent
18a04afa8c
commit
bbf936f40d
@@ -922,7 +922,7 @@ class MassMailing(models.Model):
|
||||
"""
|
||||
|
||||
# Apply same 'get email field' rule from mail_thread.message_get_default_recipients
|
||||
if 'partner_id' in target._fields:
|
||||
if 'partner_id' in target._fields and target._fields['partner_id'].store:
|
||||
mail_field = 'email'
|
||||
query = """
|
||||
SELECT lower(substring(p.%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)'))
|
||||
@@ -935,11 +935,11 @@ class MassMailing(models.Model):
|
||||
"""
|
||||
elif issubclass(type(target), self.pool['mail.thread.blacklist']):
|
||||
mail_field = 'email_normalized'
|
||||
elif 'email_from' in target._fields:
|
||||
elif 'email_from' in target._fields and target._fields['email_from'].store:
|
||||
mail_field = 'email_from'
|
||||
elif 'partner_email' in target._fields:
|
||||
elif 'partner_email' in target._fields and target._fields['partner_email'].store:
|
||||
mail_field = 'partner_email'
|
||||
elif 'email' in target._fields:
|
||||
elif 'email' in target._fields and target._fields['email'].store:
|
||||
mail_field = 'email'
|
||||
else:
|
||||
raise UserError(_("Unsupported mass mailing model %s", self.mailing_model_id.name))
|
||||
|
||||
@@ -178,16 +178,19 @@ class Mailing(models.Model):
|
||||
if issubclass(type(target), self.pool['mail.thread.phone']):
|
||||
phone_fields = ['phone_sanitized']
|
||||
elif issubclass(type(target), self.pool['mail.thread']):
|
||||
phone_fields = target._sms_get_number_fields()
|
||||
phone_fields = [
|
||||
fname for fname in target._sms_get_number_fields()
|
||||
if fname in target._fields and target._fields[fname].store
|
||||
]
|
||||
partner_fields = target._sms_get_partner_fields()
|
||||
else:
|
||||
phone_fields = []
|
||||
if 'mobile' in target._fields:
|
||||
if 'mobile' in target._fields and target._fields['mobile'].store:
|
||||
phone_fields.append('mobile')
|
||||
if 'phone' in target._fields:
|
||||
if 'phone' in target._fields and target._fields['phone'].store:
|
||||
phone_fields.append('phone')
|
||||
partner_field = next(
|
||||
(fname for fname in partner_fields if target._fields[fname].type == 'many2one'),
|
||||
(fname for fname in partner_fields if target._fields[fname].store and target._fields[fname].type == 'many2one'),
|
||||
False
|
||||
)
|
||||
if not phone_fields and not partner_field:
|
||||
|
||||
Reference in New Issue
Block a user