From aed71fc8970ae73ada2bd0bd2407ee120b1a2155 Mon Sep 17 00:00:00 2001 From: Yolann Sabaux Date: Fri, 29 Apr 2022 12:18:04 +0000 Subject: [PATCH] [FIX] mass_mailing: allow duplicate in test mode Steps to reproduce: - In Marketing Automation - Campaigns - Select the demo campaign - Click on "Launch a test" - Select Brandon - Send the two mails from the campaign - Redo all the steps with a new Test but the same contact Issue: - The mails won't be sent Cause: - Since for this campaign we already sent these mails to Brandon, the mails will be considered as duplicate in: https://github.com/odoo/odoo/blob/11b7d89114178fa43545fb8e6224cb4ccbcf8ec1/addons/mail/wizard/mail_compose_message.py#L499 Solution: We want to make sure that: - when doing a test, since there is only one linked partner to it, we can send as many mails as we launch tests. -> repeated tests make sense as we want to fine tune campaigns and maybe get feedback from actual customers - when launching the actual campaign, there are no duplicates (normal flow) but that eventual test-customers receive the final campaign In order to do that, we have to filter out from the seen_list https://github.com/odoo/odoo/blob/9b25a4b5a782146e8c0b41eb75ceea7ac3cd3abf/addons/mass_mailing/models/mailing.py#L736 the test-records. opw-2810298 closes odoo/odoo#92062 X-original-commit: 4cebf53aa89c21ef255f5d5da450fdf98c4c9ac1 Related: odoo/enterprise#27660 Signed-off-by: yosa-odoo Signed-off-by: Thibault Delavallee (tde) --- addons/mass_mailing/models/mailing.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index 5cad182f4a3..479fa46d47f 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -839,7 +839,9 @@ class MassMailing(models.Model): SELECT lower(substring(t.%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)')) FROM mailing_trace s JOIN %(target)s t ON (s.res_id = t.id) + %(join_domain)s WHERE substring(t.%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)') IS NOT NULL + %(where_domain)s """ # Apply same 'get email field' rule from mail_thread.message_get_default_recipients @@ -850,7 +852,9 @@ class MassMailing(models.Model): FROM mailing_trace s JOIN %(target)s t ON (s.res_id = t.id) JOIN res_partner p ON (t.partner_id = p.id) + %(join_domain)s WHERE substring(p.%(mail_field)s, '([^ ,;<@]+@[^> ,;]+)') IS NOT NULL + %(where_domain)s """ elif issubclass(type(target), self.pool['mail.thread.blacklist']): mail_field = 'email_normalized' @@ -872,7 +876,8 @@ class MassMailing(models.Model): AND s.mass_mailing_id = %%(mailing_id)s AND s.model = %%(target_model)s; """ - query = query % {'target': target._table, 'mail_field': mail_field} + join_domain, where_domain = self._get_seen_list_extra() + query = query % {'target': target._table, 'mail_field': mail_field, 'join_domain': join_domain, 'where_domain': where_domain} params = {'mailing_id': self.id, 'mailing_campaign_id': self.campaign_id.id, 'target_model': self.mailing_model_real} self._cr.execute(query, params) seen_list = set(m[0] for m in self._cr.fetchall()) @@ -880,6 +885,9 @@ class MassMailing(models.Model): "Mass-mailing %s has already reached %s %s emails", self, len(seen_list), target._name) return seen_list + def _get_seen_list_extra(self): + return ('', '') + def _get_mass_mailing_context(self): """Returns extra context items with pre-filled blacklist and seen list for massmailing""" return {