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.

32 lines
1.2 KiB

  1. # Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import models, api, fields
  4. class ResPartner(models.Model):
  5. _name = 'res.partner'
  6. _inherit = ['res.partner', 'mail.bounced.mixin']
  7. # tracking_emails_count and email_score are non-store fields in order
  8. # to improve performance
  9. tracking_emails_count = fields.Integer(
  10. compute='_compute_tracking_emails_count', readonly=True)
  11. email_score = fields.Float(compute='_compute_email_score', readonly=True)
  12. @api.depends('email')
  13. def _compute_email_score(self):
  14. for partner in self.filtered('email'):
  15. partner.email_score = self.env['mail.tracking.email'].\
  16. email_score_from_email(partner.email)
  17. @api.multi
  18. @api.depends('email')
  19. def _compute_tracking_emails_count(self):
  20. for partner in self:
  21. count = 0
  22. if partner.email:
  23. count = self.env['mail.tracking.email'].search_count([
  24. ('recipient_address', '=', partner.email.lower())
  25. ])
  26. partner.tracking_emails_count = count