Browse Source

[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`.
pull/323/head
Pedro M. Baeza 5 years ago
parent
commit
007d8ada83
  1. 3
      mail_tracking/__manifest__.py
  2. 17
      mail_tracking/models/mail_bounced_mixin.py

3
mail_tracking/__manifest__.py

@ -1,12 +1,13 @@
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
# Copyright 2018 David Vidal - <david.vidal@tecnativa.com> # Copyright 2018 David Vidal - <david.vidal@tecnativa.com>
# Copyright 2018 Tecnativa - Ernesto Tejeda # Copyright 2018 Tecnativa - Ernesto Tejeda
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Email tracking", "name": "Email tracking",
"summary": "Email tracking system for all mails sent", "summary": "Email tracking system for all mails sent",
"version": "12.0.1.0.0",
"version": "12.0.1.0.1",
"category": "Social Network", "category": "Social Network",
"website": "http://github.com/OCA/social", "website": "http://github.com/OCA/social",
"author": "Tecnativa, " "author": "Tecnativa, "

17
mail_tracking/models/mail_bounced_mixin.py

@ -24,20 +24,25 @@ class MailBouncedMixin(models.AbstractModel):
def email_bounced_set(self, tracking_emails, reason, event=None): def email_bounced_set(self, tracking_emails, reason, event=None):
"""Inherit this method to make any other actions to the model that """Inherit this method to make any other actions to the model that
inherit the mixin""" 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) partners = self.filtered(lambda r: not r.email_bounced)
return partners.write({'email_bounced': True}) return partners.write({'email_bounced': True})
def write(self, vals): def write(self, vals):
[email_field] = self._primary_email [email_field] = self._primary_email
if email_field not in vals: 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 email = vals[email_field].lower() if vals[email_field] else False
mte_obj = self.env['mail.tracking.email'] 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) res = mte_obj._email_last_tracking_state(email)
tracking = mte_obj.browse(res[0].get('id')) tracking = mte_obj.browse(res[0].get('id'))
event = tracking.tracking_event_ids[:1] 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…
Cancel
Save