You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # Copyright 2017 Vicent Cubells - <vicent.cubells@tecnativa.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import models, api, fields
  6. class MailMassMailingContact(models.Model):
  7. _inherit = 'mail.mass_mailing.contact'
  8. email_bounced = fields.Boolean(string="Email bounced")
  9. email_score = fields.Float(
  10. string="Email score", readonly=True, store=False,
  11. compute='_compute_email_score')
  12. @api.multi
  13. @api.depends('email')
  14. def _compute_email_score(self):
  15. for contact in self.filtered('email'):
  16. contact.email_score = self.env['mail.tracking.email'].\
  17. email_score_from_email(contact.email)
  18. @api.multi
  19. def email_bounced_set(self, tracking_emails, reason, event=None):
  20. contacts = self.filtered(lambda r: not r.email_bounced)
  21. return contacts.write({'email_bounced': True})
  22. @api.multi
  23. def write(self, vals):
  24. email = vals.get('email')
  25. if email is not None:
  26. vals['email_bounced'] = (
  27. bool(email) and
  28. self.env['mail.tracking.email'].email_is_bounced(email))
  29. return super(MailMassMailingContact, self).write(vals)