Skip to content
Permalink
Browse files

[FIX] mass_mailing: support partner_id field

Backport of 83b37a8 to 11.0
sale.order but also event.track need to use partner_id as email field

Fixes #31954
Closes #31967
  • Loading branch information...
JKE-be authored and mart-e committed Mar 20, 2019
1 parent a404929 commit ae333a2d9906b0b67503cb5bd7493a5f9705d447
Showing with 22 additions and 9 deletions.
  1. +22 −9 addons/mass_mailing/models/mass_mailing.py
@@ -616,15 +616,28 @@ def _get_seen_list(self):
"""Returns a set of emails already targeted by current mailing/campaign (no duplicates)"""
self.ensure_one()
target = self.env[self.mailing_model_real]
mail_field = 'email' if 'email' in target._fields else 'email_from'
# avoid loading a large number of records in memory
# + use a basic heuristic for extracting emails
query = """
SELECT lower(substring(%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)'))
FROM mail_mail_statistics s
JOIN %(target)s t ON (s.res_id = t.id)
WHERE substring(%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)') IS NOT NULL
"""
if set(['email', 'email_from']) & set(target._fields):
mail_field = 'email' if 'email' in target._fields else 'email_from'
# avoid loading a large number of records in memory
# + use a basic heuristic for extracting emails
query = """
SELECT lower(substring(%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)'))
FROM mail_mail_statistics s
JOIN %(target)s t ON (s.res_id = t.id)
WHERE substring(%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)') IS NOT NULL
"""
elif 'partner_id' in target._fields:
mail_field = 'email'
query = """
SELECT lower(substring(p.%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)'))
FROM mail_mail_statistics s
JOIN %(target)s t ON (s.res_id = t.id)
JOIN res_partner p ON (t.partner_id = p.id)
WHERE substring(p.%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)') IS NOT NULL
"""
else:
raise UserError(_("Unsupported mass mailing model %s") % self.mailing_model_id.name)

if self.mass_mailing_campaign_id.unique_ab_testing:
query +="""
AND s.mass_mailing_campaign_id = %%(mailing_campaign_id)s;

0 comments on commit ae333a2

Please sign in to comment.
You can’t perform that action at this time.