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