From 1e3f2f2e310cf29f6a26a69f59629c743ebb7a56 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 12 Sep 2016 17:50:59 +0200 Subject: [PATCH] Avoid duplicate error. By indicating the exact `partner_id` and ensuring no contacts associated to it are found, you avoid possible duplication errors when several partners share the same name or email. --- mass_mailing_partner/wizard/partner_mail_list_wizard.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mass_mailing_partner/wizard/partner_mail_list_wizard.py b/mass_mailing_partner/wizard/partner_mail_list_wizard.py index 94e1065b..cdf34752 100644 --- a/mass_mailing_partner/wizard/partner_mail_list_wizard.py +++ b/mass_mailing_partner/wizard/partner_mail_list_wizard.py @@ -24,12 +24,17 @@ class PartnerMailListWizard(models.TransientModel): for partner in self.partner_ids: if not partner.email: raise UserError(_("Partner '%s' has no email.") % partner.name) - criteria = [('email', '=', partner.email), - ('list_id', '=', self.mail_list_id.id)] + criteria = [ + '|', + ('email', '=', partner.email), + ('partner_id', '=', partner.id), + ('list_id', '=', self.mail_list_id.id), + ] contact_test = contact_obj.search(criteria) if contact_test: continue contact_vals = { + 'partner_id': partner.id, 'email': partner.email, 'name': partner.name, 'list_id': self.mail_list_id.id