Skip to content

Commit

Permalink
Various Mailchimp fixes
Browse files Browse the repository at this point in the history
- Sync was missing when tags were updated
- FIX for partners merging: merge also mailing contacts
- Bug fixes in the code
  • Loading branch information
ecino committed Jun 10, 2021
1 parent 0043898 commit 220da19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mass_mailing_switzerland/models/mailchimp_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def process_member_from_stored_response(self, pending_record):
@api.multi
def get_mapped_merge_field(self):
res = super().get_mapped_merge_field()
res.extend(["lastname", "firstname", "number_sponsorships", "opt_out"])
res.extend([
"lastname", "firstname", "number_sponsorships", "opt_out", "category_id"])
return res
16 changes: 14 additions & 2 deletions mass_mailing_switzerland/models/mass_mailing_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ def create(self, vals_list):

@api.multi
def write(self, values):
if values.get("email"):
# Check for duplicates when changing the email.
changed = self.filtered(lambda c: c.email != values["email"])
other_contacts = self.search([
("email", "=", values["email"]),
("id", "not in", changed.ids)
])
if other_contacts:
values["partner_ids"] = [(4, c.id) for c in self.mapped("partner_ids")]
changed.delay_contact_unlink()
return super(MassMailingContact, other_contacts).write(values)
out = super().write(values)
# can't be simplified because we are looking for is_email_valid == False
# AND is_email_valid is in values (return None otherwise)
Expand Down Expand Up @@ -213,7 +224,8 @@ def process_mailchimp_update(self):
])
to_update = self
if queue_job:
args = ",".join(queue_job.mapped("args"))
args = [
item for sublist in queue_job.mapped("args") for item in sublist]
for contact in self:
if contact.id in args:
to_update -= contact
Expand All @@ -232,7 +244,7 @@ def action_export_to_mailchimp(self):
@api.multi
@job(default_channel="root.mass_mailing_switzerland.update_partner_mailchimp")
def action_update_to_mailchimp(self):
"""
"""Synchronize Contacts to Mailchimp.
Always export in english so that all tags are set in English
"""
out = True
Expand Down
3 changes: 2 additions & 1 deletion mass_mailing_switzerland/models/res_partner_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ def update_partner_tags(self):
"tag_ids": [(4, tag.id)]
})
to_update = old_partners ^ new_partners
to_update.mapped("mass_mailing_contact_ids").process_mailchimp_update()
self.env["res.partner"].browse(to_update).mapped(
"mass_mailing_contact_ids").process_mailchimp_update()
return True

0 comments on commit 220da19

Please sign in to comment.