Skip to content

Commit

Permalink
Improve mailchimp error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Jun 16, 2022
1 parent cddd448 commit 10b7867
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions mass_mailing_switzerland/models/mass_mailing_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,23 @@ def action_update_to_mailchimp(self):
# Email field in odoo and mailchimp are now different.
# solution : we remove previous link to mailchimp and export
# the contact with new mail
if e.args[0] and literal_eval(e.args[0])['status'] == 404:
self.env.clear()
available_mailchimp_lists = self.env['mailchimp.lists'].search([])
lists = available_mailchimp_lists.mapped('odoo_list_id').ids
contact_to_update.subscription_list_ids.filtered(
lambda x: x.list_id.id in lists).write({"mailchimp_id": False})
# raise exception if it's any other type
else:
raise e
try:
if e.args[0] and literal_eval(e.args[0])['status'] == 404:
self.env.clear()
available_mailchimp_lists = self.env['mailchimp.lists'].search([])
lists = available_mailchimp_lists.mapped('odoo_list_id').ids
contact_to_update.subscription_list_ids.filtered(
lambda x: x.list_id.id in lists).write({"mailchimp_id": False})
# raise exception if it's any other type
else:
raise e

# once link is removed member can again be exported to mailchimp
out = out and super(MassMailingContact,
contact_to_update).action_export_to_mailchimp()
# once link is removed member can again be exported to mailchimp
out = out and super(MassMailingContact,
contact_to_update).action_export_to_mailchimp()
except:
logger.warning("Mailchimp error is not correctly processed.")
raise e
return out

@api.multi
Expand Down

0 comments on commit 10b7867

Please sign in to comment.