From a7fac21db8c24fa4ac994739137b5cce308968ac Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Fri, 9 Sep 2016 18:31:25 +0200 Subject: [PATCH] [FIX] Update email_score when email changes --- mail_tracking/models/mail_tracking_email.py | 7 +++++++ mail_tracking/models/res_partner.py | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mail_tracking/models/mail_tracking_email.py b/mail_tracking/models/mail_tracking_email.py index 6b2944be..d498ad66 100644 --- a/mail_tracking/models/mail_tracking_email.py +++ b/mail_tracking/models/mail_tracking_email.py @@ -126,6 +126,13 @@ class MailTrackingEmail(models.Model): # Consider only last 10 tracking emails return self.sorted(key=lambda r: r.time, reverse=True)[:10] + @api.model + def email_score_from_email(self, email): + trackings = self.env['mail.tracking.email'].search([ + ('recipient_address', '=ilike', email) + ]) + return trackings.email_score() + @api.multi def email_score(self): """Default email score algorimth""" diff --git a/mail_tracking/models/res_partner.py b/mail_tracking/models/res_partner.py index c4eb294a..908f1190 100644 --- a/mail_tracking/models/res_partner.py +++ b/mail_tracking/models/res_partner.py @@ -40,6 +40,7 @@ class ResPartner(models.Model): def write(self, vals): email = vals.get('email') if email is not None: - vals['tracking_email_ids'] = \ - self.env['mail.tracking.email']._tracking_ids_to_write(email) + m_track = self.env['mail.tracking.email'] + vals['tracking_email_ids'] = m_track._tracking_ids_to_write(email) + vals['email_score'] = m_track.email_score_from_email(email) return super(ResPartner, self).write(vals)