Skip to content

Commit

Permalink
[IMP][8.0][mass_mailing_partner] Sync opt_out.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yajo committed May 30, 2016
1 parent c5aa7d5 commit efc4ca2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mass_mailing_partner/models/mail_mass_mailing_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ 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):
if vals.get('partner_id', None) is False:
# 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 = {
Expand Down Expand Up @@ -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

0 comments on commit efc4ca2

Please sign in to comment.