2018-03-19 16:41:26 +01:00
|
|
|
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
|
2016-06-14 17:22:17 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
2016-10-14 21:53:04 +02:00
|
|
|
from odoo import models, api, fields
|
2016-06-14 17:22:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model):
|
2018-11-05 17:26:01 +01:00
|
|
|
_name = 'res.partner'
|
|
|
|
_inherit = ['res.partner', 'mail.bounced.mixin']
|
2016-06-14 17:22:17 +02:00
|
|
|
|
2016-10-14 15:42:29 +02:00
|
|
|
# tracking_emails_count and email_score are non-store fields in order
|
|
|
|
# to improve performance
|
2016-06-14 17:22:17 +02:00
|
|
|
tracking_emails_count = fields.Integer(
|
2016-10-14 15:42:29 +02:00
|
|
|
compute='_compute_tracking_emails_count', readonly=True)
|
|
|
|
email_score = fields.Float(compute='_compute_email_score', readonly=True)
|
|
|
|
|
|
|
|
@api.depends('email')
|
|
|
|
def _compute_email_score(self):
|
|
|
|
for partner in self.filtered('email'):
|
|
|
|
partner.email_score = self.env['mail.tracking.email'].\
|
|
|
|
email_score_from_email(partner.email)
|
2016-06-14 17:22:17 +02:00
|
|
|
|
2016-10-14 15:42:29 +02:00
|
|
|
@api.multi
|
|
|
|
@api.depends('email')
|
2016-06-14 17:22:17 +02:00
|
|
|
def _compute_tracking_emails_count(self):
|
2016-10-14 21:53:04 +02:00
|
|
|
for partner in self:
|
2016-10-24 13:35:45 +02:00
|
|
|
count = 0
|
|
|
|
if partner.email:
|
|
|
|
count = self.env['mail.tracking.email'].search_count([
|
|
|
|
('recipient_address', '=', partner.email.lower())
|
2016-10-14 21:53:04 +02:00
|
|
|
])
|
2016-10-24 13:35:45 +02:00
|
|
|
partner.tracking_emails_count = count
|