From c76a903ba4c4abcbd64bc901d65700c043ec6676 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Mar 2021 20:58:05 +0000 Subject: [PATCH] [FIX] fixes cooperator validation with same email for company and representative --- easy_my_coop/models/coop.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index a8ba624..23bad29 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -699,10 +699,17 @@ class SubscriptionRequest(models.Model): if self.is_company and not partner.has_representative(): contact = False if self.email: - domain = [("email", "=", self.email)] + domain = [("email", "=", self.email), + ('company_type', '=', 'person')] contact = partner_obj.search(domain) - if contact: + if len(contact) < 2: contact.type = "representative" + else: + raise UserError( + _( + "You have duplicate contact with email %s" % self.email + ) + ) if not contact: contact_vals = self.get_representative_vals() partner_obj.create(contact_vals)