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.

40 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api, fields
  5. class ResPartner(models.Model):
  6. _inherit = 'res.partner'
  7. tracking_email_ids = fields.Many2many(
  8. string="Tracking emails", comodel_name="mail.tracking.email",
  9. readonly=True)
  10. tracking_emails_count = fields.Integer(
  11. string="Tracking emails count", store=True, readonly=True,
  12. compute="_compute_tracking_emails_count")
  13. email_score = fields.Float(
  14. string="Email score",
  15. compute="_compute_email_score", store=True, readonly=True)
  16. @api.one
  17. @api.depends('tracking_email_ids.state')
  18. def _compute_email_score(self):
  19. self.email_score = self.tracking_email_ids.email_score()
  20. @api.one
  21. @api.depends('tracking_email_ids')
  22. def _compute_tracking_emails_count(self):
  23. self.tracking_emails_count = self.env['mail.tracking.email'].\
  24. search_count([
  25. ('recipient_address', '=ilike', self.email)
  26. ])
  27. @api.multi
  28. def write(self, vals):
  29. email = vals.get('email')
  30. if email is not None:
  31. vals['tracking_email_ids'] = \
  32. self.env['mail.tracking.email']._tracking_ids_to_write(email)
  33. return super(ResPartner, self).write(vals)