[FIX] mass_mailing: support partner_id field
Manual cherrypick of 83b37a8
sale.order but also event.track need to use partner_id as email field
Closes #31954
closes odoo/odoo#31967
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
@@ -1686,6 +1686,12 @@ msgstr ""
|
||||
msgid "Unsubscription Date"
|
||||
msgstr ""
|
||||
|
||||
#. module: mass_mailing
|
||||
#: code:addons/mass_mailing/models/mass_mailing.py:639
|
||||
#, python-format
|
||||
msgid "Unsupported mass mailing model %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: mass_mailing
|
||||
#: model:ir.ui.view,arch_db:mass_mailing.s_mail_block_paragraph
|
||||
msgid "Usability improvements made on Odoo will automatically apply to all\n"
|
||||
|
||||
@@ -616,15 +616,28 @@ class MassMailing(models.Model):
|
||||
"""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;
|
||||
|
||||
Reference in New Issue
Block a user