[FIX] survey_record_generation: partner_id/email on survey.user_input could be wrong
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 2m45s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 2m45s
New version : 16.0.1.0.3 _mark_done() only set partner_id/email when it created a *new* res.partner. If the answer already had a partner_id/email (e.g. inherited from the Odoo user logged in when the /survey/start link was opened), that value was kept even though the record creation matched or created a different, correct contact from the participant's own answers. Now we always sync partner_id/email to the res.partner actually matched or created from the participant's answers. Add a migration to relink partner_id/email on existing done submissions. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,7 @@ class SurveyUserInput(models.Model):
|
||||
for user_input in self:
|
||||
created_records = {}
|
||||
other_record_fields_to_update: list[SurveyRecordCreationFieldValues] = []
|
||||
partner_linked_in_this_run = False
|
||||
|
||||
record_creation: SurveyRecordCreation
|
||||
for (
|
||||
@@ -85,8 +86,6 @@ class SurveyUserInput(models.Model):
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
record = self.env[model].create(vals)
|
||||
if model == "res.partner" and not self.partner_id:
|
||||
self.partner_id = record.id
|
||||
except Exception:
|
||||
# This a broad exception because it could be IntegrityError,
|
||||
# EmptyNamesError in case partner_firstname is installed etc...
|
||||
@@ -103,6 +102,17 @@ class SurveyUserInput(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
if model == "res.partner" and not partner_linked_in_this_run:
|
||||
# Always reflect the partner actually matched/created from
|
||||
# this participant's own answers, even if partner_id/email
|
||||
# were already set on the answer (e.g. inherited from the
|
||||
# logged-in user when the survey link was opened). Only the
|
||||
# first res.partner record creation of this run wins, in
|
||||
# case several are configured on the same survey.
|
||||
user_input.partner_id = record.id
|
||||
user_input.email = record.email
|
||||
partner_linked_in_this_run = True
|
||||
|
||||
created_records[record_creation.id] = record
|
||||
|
||||
# update linked record
|
||||
|
||||
Reference in New Issue
Block a user