[FIX] mail_tracking: Don't call write inside other write
Or infinite recursions will happen on other `write` overwrites, like the one that happens on `mass_mailing_partner`.
This commit is contained in:
parent
cd1d3be640
commit
71b67a5475
@ -1,12 +1,13 @@
|
||||
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
||||
# Copyright 2018 David Vidal - <david.vidal@tecnativa.com>
|
||||
# Copyright 2018 Tecnativa - Ernesto Tejeda
|
||||
# Copyright 2019 Tecnativa - Pedro M. Baeza
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Email tracking",
|
||||
"summary": "Email tracking system for all mails sent",
|
||||
"version": "12.0.1.0.0",
|
||||
"version": "12.0.1.0.1",
|
||||
"category": "Social Network",
|
||||
"website": "http://github.com/OCA/social",
|
||||
"author": "Tecnativa, "
|
||||
|
@ -24,20 +24,25 @@ class MailBouncedMixin(models.AbstractModel):
|
||||
def email_bounced_set(self, tracking_emails, reason, event=None):
|
||||
"""Inherit this method to make any other actions to the model that
|
||||
inherit the mixin"""
|
||||
if self.env.context.get('write_loop'):
|
||||
# We avoid with the context an infinite recursion calling write
|
||||
# method from other write method.
|
||||
return True
|
||||
partners = self.filtered(lambda r: not r.email_bounced)
|
||||
return partners.write({'email_bounced': True})
|
||||
|
||||
def write(self, vals):
|
||||
[email_field] = self._primary_email
|
||||
if email_field not in vals:
|
||||
return super(MailBouncedMixin, self).write(vals)
|
||||
return super().write(vals)
|
||||
email = vals[email_field].lower() if vals[email_field] else False
|
||||
mte_obj = self.env['mail.tracking.email']
|
||||
if not mte_obj.email_is_bounced(email):
|
||||
vals['email_bounced'] = False
|
||||
return super(MailBouncedMixin, self).write(vals)
|
||||
vals['email_bounced'] = mte_obj.email_is_bounced(email)
|
||||
if vals['email_bounced']:
|
||||
res = mte_obj._email_last_tracking_state(email)
|
||||
tracking = mte_obj.browse(res[0].get('id'))
|
||||
event = tracking.tracking_event_ids[:1]
|
||||
self.email_bounced_set(tracking, event.error_details, event)
|
||||
return super(MailBouncedMixin, self).write(vals)
|
||||
self.with_context(
|
||||
write_loop=True,
|
||||
).email_bounced_set(tracking, event.error_details, event)
|
||||
return super().write(vals)
|
||||
|
Loading…
Reference in New Issue
Block a user