social/mail_tracking/models/res_partner.py

31 lines
1.2 KiB
Python
Raw Normal View History

2018-03-19 16:41:26 +01:00
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2019-11-18 11:46:59 +01:00
from odoo import api, fields, models
class ResPartner(models.Model):
2019-11-18 11:46:59 +01:00
_name = "res.partner"
_inherit = ["res.partner", "mail.bounced.mixin"]
# tracking_emails_count and email_score are non-store fields in order
# to improve performance
tracking_emails_count = fields.Integer(
2019-11-18 11:34:02 +01:00
compute="_compute_email_score_and_count", readonly=True
2019-11-18 11:46:59 +01:00
)
2019-11-18 11:34:02 +01:00
email_score = fields.Float(compute="_compute_email_score_and_count", readonly=True)
2019-11-18 11:46:59 +01:00
@api.depends("email")
2019-11-18 11:34:02 +01:00
def _compute_email_score_and_count(self):
partners_mail = self.filtered("email")
mail_tracking_obj = self.env["mail.tracking.email"]
for partner in partners_mail:
partner.email_score = self.env[
"mail.tracking.email"
].email_score_from_email(partner.email)
partner.tracking_emails_count = mail_tracking_obj.search_count(
[("recipient_address", "=", partner.email.lower())]
)
partners_no_mail = self - partners_mail
partners_no_mail.update({"email_score": 50.0, "tracking_emails_count": 0})