[IMP] survey_contact_generation:

Change doublon search on survey contact generation
This commit is contained in:
clementthomas
2024-02-27 11:40:50 +01:00
parent afb1be4c47
commit 33796a943a
2 changed files with 16 additions and 5 deletions

View File

@@ -10,7 +10,7 @@
"author": "Tecnativa, Odoo Community Association (OCA)", "author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["clement_thomas"], "maintainers": ["clement_thomas"],
"license": "AGPL-3", "license": "AGPL-3",
"depends": ["survey"], "depends": ["survey","partner_firstname"],
"data": [ "data": [
"views/survey_question_views.xml", "views/survey_question_views.xml",
"views/survey_survey_views.xml", "views/survey_survey_views.xml",

View File

@@ -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 lambda r: r.survey_id.generate_contact# and not self.partner_id #uncomment to avoid contact generation several times
): ):
vals = user_input._prepare_partner() vals = user_input._prepare_partner()
partner = False partner = False
email = vals.get("email") 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: if email:
partner = self.env["res.partner"].search( doublon_domain.append(("email", "ilike", email))
[("email", "=", email)], limit=1 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: if not partner:
partner = self.env["res.partner"].create(vals) partner = self.env["res.partner"].create(vals)
self._create_contact_post_process(partner) self._create_contact_post_process(partner)