From 33796a943a002b8793a985dc1e9c66f40b0357a7 Mon Sep 17 00:00:00 2001 From: clementthomas Date: Tue, 27 Feb 2024 11:40:50 +0100 Subject: [PATCH] [IMP] survey_contact_generation: Change doublon search on survey contact generation --- survey_contact_generation/__manifest__.py | 2 +- .../models/survey_user_input.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/survey_contact_generation/__manifest__.py b/survey_contact_generation/__manifest__.py index 8138023..0b5145c 100644 --- a/survey_contact_generation/__manifest__.py +++ b/survey_contact_generation/__manifest__.py @@ -10,7 +10,7 @@ "author": "Tecnativa, Odoo Community Association (OCA)", "maintainers": ["clement_thomas"], "license": "AGPL-3", - "depends": ["survey"], + "depends": ["survey","partner_firstname"], "data": [ "views/survey_question_views.xml", "views/survey_survey_views.xml", diff --git a/survey_contact_generation/models/survey_user_input.py b/survey_contact_generation/models/survey_user_input.py index b47ca1e..65b88f0 100644 --- a/survey_contact_generation/models/survey_user_input.py +++ b/survey_contact_generation/models/survey_user_input.py @@ -64,12 +64,23 @@ class SurveyUserInput(models.Model): lambda r: r.survey_id.generate_contact# and not self.partner_id #uncomment to avoid contact generation several times ): vals = user_input._prepare_partner() - partner = False + partner = False email = vals.get("email") + firstname = vals.get("firstname") + lastname = vals.get("lastname") + + #search if partner exists with same email, firstname and lastname depending on submitted data + doublon_domain = [] if email: - partner = self.env["res.partner"].search( - [("email", "=", email)], limit=1 - ) + doublon_domain.append(("email", "ilike", email)) + if firstname: + doublon_domain.append(("firstname", "ilike", firstname)) + if lastname: + doublon_domain.append(("lastname", "ilike", lastname)) + + if doublon_domain: + partner = self.env["res.partner"].search(doublon_domain, limit=1) + if not partner: partner = self.env["res.partner"].create(vals) self._create_contact_post_process(partner)