[FIX] mass_mailing: properly handle multiple bounced_partner
It may be a recordset in case of partner duplicates. The variable bounced_partner is simple search by email: https://github.com/odoo/odoo/blob/72b5a17fc0e6f439d462647a7b55c9a26235a8df/addons/mail/models/mail_thread.py#L1349 closes odoo/odoo#75139 X-original-commit: 9c827ff7c5e69ba97105e36bf43c7d44860981dc Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Ivan Yelizariev // IEL <yelizariev@users.noreply.github.com>
This commit is contained in:
@@ -57,7 +57,7 @@ class MailThread(models.AbstractModel):
|
||||
if bounced_email:
|
||||
three_months_ago = fields.Datetime.to_string(datetime.datetime.now() - datetime.timedelta(weeks=13))
|
||||
stats = self.env['mailing.trace'].search(['&', ('bounced', '>', three_months_ago), ('email', '=ilike', bounced_email)]).mapped('bounced')
|
||||
if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT and (not bounced_partner or bounced_partner.message_bounce >= BLACKLIST_MAX_BOUNCED_LIMIT):
|
||||
if len(stats) >= BLACKLIST_MAX_BOUNCED_LIMIT and (not bounced_partner or any(p.message_bounce >= BLACKLIST_MAX_BOUNCED_LIMIT for p in bounced_partner)):
|
||||
if max(stats) > min(stats) + datetime.timedelta(weeks=1):
|
||||
blacklist_rec = self.env['mail.blacklist'].sudo()._add(bounced_email)
|
||||
blacklist_rec._message_log(
|
||||
|
||||
@@ -5,21 +5,52 @@ import datetime
|
||||
|
||||
from odoo.addons.test_mass_mailing.tests import common
|
||||
from odoo.tests.common import users
|
||||
from odoo.addons.mass_mailing.models.mail_thread import BLACKLIST_MAX_BOUNCED_LIMIT
|
||||
|
||||
|
||||
class TestAutoBlacklist(common.TestMassMailCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAutoBlacklist, cls).setUpClass()
|
||||
cls.target_rec = cls._create_mailing_test_records()[0]
|
||||
cls.mailing_bl.write({'mailing_domain': [('id', 'in', cls.target_rec.ids)]})
|
||||
|
||||
@users('user_marketing')
|
||||
def test_mailing_bounce_w_auto_bl(self):
|
||||
self._test_mailing_bounce_w_auto_bl(None)
|
||||
|
||||
@users('user_marketing')
|
||||
def test_mailing_bounce_w_auto_bl_partner(self):
|
||||
bounced_partner = self.env['res.partner'].sudo().create({
|
||||
'name': 'Bounced Partner',
|
||||
'email': self.target_rec.email_from,
|
||||
'message_bounce': BLACKLIST_MAX_BOUNCED_LIMIT,
|
||||
})
|
||||
self._test_mailing_bounce_w_auto_bl({'bounced_partner': bounced_partner})
|
||||
|
||||
@users('user_marketing')
|
||||
def test_mailing_bounce_w_auto_bl_partner_duplicates(self):
|
||||
bounced_partners = self.env['res.partner'].sudo().create({
|
||||
'name': 'Bounced Partner1',
|
||||
'email': self.target_rec.email_from,
|
||||
'message_bounce': BLACKLIST_MAX_BOUNCED_LIMIT,
|
||||
}) | self.env['res.partner'].sudo().create({
|
||||
'name': 'Bounced Partner2',
|
||||
'email': self.target_rec.email_from,
|
||||
'message_bounce': BLACKLIST_MAX_BOUNCED_LIMIT,
|
||||
})
|
||||
self._test_mailing_bounce_w_auto_bl({'bounced_partner': bounced_partners})
|
||||
|
||||
def _test_mailing_bounce_w_auto_bl(self, bounce_base_values):
|
||||
mailing = self.env['mailing.mailing'].browse(self.mailing_bl.ids)
|
||||
target = self._create_mailing_test_records()[0]
|
||||
mailing.write({'mailing_domain': [('id', 'in', target.ids)]})
|
||||
target = self.env['mailing.test.blacklist'].browse(self.target_rec.ids)
|
||||
|
||||
# create bounced history of 4 statistics
|
||||
for idx in range(4):
|
||||
new_mailing = mailing.copy()
|
||||
self._create_bounce_trace(new_mailing, target, dt=datetime.datetime.now() - datetime.timedelta(weeks=idx+2))
|
||||
self.gateway_mail_bounce(new_mailing, target)
|
||||
self.gateway_mail_bounce(new_mailing, target, bounce_base_values)
|
||||
|
||||
# mass mail record: ok, not blacklisted yet
|
||||
mailing.action_put_in_queue()
|
||||
@@ -33,7 +64,7 @@ class TestAutoBlacklist(common.TestMassMailCommon):
|
||||
)
|
||||
|
||||
# call bounced
|
||||
self.gateway_mail_bounce(mailing, target)
|
||||
self.gateway_mail_bounce(mailing, target, bounce_base_values)
|
||||
|
||||
# check blacklist
|
||||
blacklist_record = self.env['mail.blacklist'].sudo().search([('email', '=', target.email_normalized)])
|
||||
|
||||
Reference in New Issue
Block a user