From efc4ca2d3b336142f83411233e3d9079b186375b Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 30 May 2016 13:14:14 +0200 Subject: [PATCH] [IMP][8.0][mass_mailing_partner] Sync opt_out. If you create or update a contact that is linked to a partner and set a value for opt_out, then that value will be set on the partner too. --- .../models/mail_mass_mailing_contact.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mass_mailing_partner/models/mail_mass_mailing_contact.py b/mass_mailing_partner/models/mail_mass_mailing_contact.py index 04692763ac3..27c611f247c 100644 --- a/mass_mailing_partner/models/mail_mass_mailing_contact.py +++ b/mass_mailing_partner/models/mail_mass_mailing_contact.py @@ -28,7 +28,9 @@ def create(self, vals): if not vals.get('partner_id'): vals = self._set_partner(vals) vals = self._set_name_email(vals) - return super(MailMassMailingContact, self).create(vals) + result = super(MailMassMailingContact, self).create(vals) + result._sync_opt_out(vals) + return result @api.one def write(self, vals): @@ -36,7 +38,9 @@ def write(self, vals): # If removing partner, search again by email vals = self._set_partner(vals) vals = self._set_name_email(vals) - return super(MailMassMailingContact, self).write(vals) + result = super(MailMassMailingContact, self).write(vals) + self._sync_opt_out(vals) + return result def _prepare_partner(self, vals, mailing_list): vals = { @@ -76,3 +80,10 @@ def _set_name_email(self, vals): vals['email'] = partner.email vals['name'] = partner.name return vals + + @api.multi + def _sync_opt_out(self, vals): + """Set partner's opt_out same as contact's.""" + if "opt_out" in vals: + for s in self.filtered("partner_id"): + self.partner_id.opt_out = self.opt_out