[FW][FIX] mail: correctly avoid increasing bounced counter two times
When a bounce has to be managed on a record already inheriting from blacklist mixin it shoudl not be counted two times: one for email-based bounce and one for "all records using that email linked to blacklist mechanism should bounce". A mechanism exists to prevent that double increase but it was not correctly done. Protection was reset in a loop. Task ID-2547347 PR odoo/odoo#72347 closes odoo/odoo#72420 X-original-commit: 6e1bca5df19392d384d7c398b7aea66b62381938 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -700,7 +700,7 @@ class MailThread(models.AbstractModel):
|
||||
for model in [bl_model for bl_model in bl_models if bl_model.model in self.env]: # transient test mode
|
||||
rec_bounce_w_email = self.env[model.model].sudo().search([('email_normalized', '=', bounced_email)])
|
||||
rec_bounce_w_email._message_receive_bounce(bounced_email, bounced_partner)
|
||||
bounced_record_done = bool(bounced_record and model.model == bounced_model and bounced_record in rec_bounce_w_email)
|
||||
bounced_record_done = bounced_record_done or (bounced_record and model.model == bounced_model and bounced_record in rec_bounce_w_email)
|
||||
|
||||
# set record as bounced unless already done due to blacklist mixin
|
||||
if bounced_record and not bounced_record_done and issubclass(type(bounced_record), self.pool['mail.thread']):
|
||||
|
||||
@@ -958,24 +958,24 @@ class TestMailgateway(TestMailCommon):
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread')
|
||||
def test_message_process_bounce_records_channel(self):
|
||||
""" Test blacklist allow to multi-bounce and auto update of mail.channel """
|
||||
self.other_record = self.env['mail.test.gateway'].create({
|
||||
other_record = self.env['mail.test.gateway'].create({
|
||||
'email_from': 'Another name <%s>' % self.partner_1.email
|
||||
})
|
||||
self.yet_other_record = self.env['mail.test.gateway'].create({
|
||||
yet_other_record = self.env['mail.test.gateway'].create({
|
||||
'email_from': 'Yet Another name <%s>' % self.partner_1.email.upper()
|
||||
})
|
||||
self.test_channel = self.env['mail.channel'].create({
|
||||
test_channel = self.env['mail.channel'].create({
|
||||
'name': 'Test',
|
||||
'channel_partner_ids': [(4, self.partner_1.id)],
|
||||
})
|
||||
self.fake_email.write({
|
||||
'model': 'mail.channel',
|
||||
'res_id': self.test_channel.id,
|
||||
'res_id': test_channel.id,
|
||||
})
|
||||
self.assertIn(self.partner_1, self.test_channel.channel_partner_ids)
|
||||
self.assertIn(self.partner_1, test_channel.channel_partner_ids)
|
||||
self.assertEqual(self.partner_1.message_bounce, 0)
|
||||
self.assertEqual(self.other_record.message_bounce, 0)
|
||||
self.assertEqual(self.yet_other_record.message_bounce, 0)
|
||||
self.assertEqual(other_record.message_bounce, 0)
|
||||
self.assertEqual(yet_other_record.message_bounce, 0)
|
||||
|
||||
extra = self.fake_email.message_id
|
||||
for i in range(10):
|
||||
@@ -983,9 +983,24 @@ class TestMailgateway(TestMailCommon):
|
||||
self.assertFalse(record)
|
||||
self.assertEqual(self.partner_1.message_bounce, 10)
|
||||
self.assertEqual(self.test_record.message_bounce, 0)
|
||||
self.assertEqual(self.other_record.message_bounce, 10)
|
||||
self.assertEqual(self.yet_other_record.message_bounce, 10)
|
||||
self.assertNotIn(self.partner_1, self.test_channel.channel_partner_ids)
|
||||
self.assertEqual(other_record.message_bounce, 10)
|
||||
self.assertEqual(yet_other_record.message_bounce, 10)
|
||||
self.assertNotIn(self.partner_1, test_channel.channel_partner_ids)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread')
|
||||
def test_message_process_bounce_records_partner(self):
|
||||
""" Test blacklist + bounce on ``res.partner`` model """
|
||||
self.assertEqual(self.partner_1.message_bounce, 0)
|
||||
self.fake_email.write({
|
||||
'model': 'res.partner',
|
||||
'res_id': self.partner_1.id,
|
||||
})
|
||||
|
||||
extra = self.fake_email.message_id
|
||||
record = self.format_and_process(test_mail_data.MAIL_BOUNCE, self.partner_1.email_formatted, 'groups@test.com', subject='Undelivered Mail Returned to Sender', extra=extra)
|
||||
self.assertFalse(record)
|
||||
self.assertEqual(self.partner_1.message_bounce, 1)
|
||||
self.assertEqual(self.test_record.message_bounce, 0)
|
||||
|
||||
# --------------------------------------------------
|
||||
# Thread formation
|
||||
|
||||
Reference in New Issue
Block a user