[FIX] survey_record_generation: questions without answer no longer empty fields
When a question was not displayed (conditional question) or skipped, its field was still given to create() with a None value. The field was then emptied instead of keeping its default or computed value. Since the link to an already created record is given at creation, this also made sale.subscription.line price_unit equal to 0 when the "free amount" question was not displayed, instead of the product price. Fields without value are now left out of the values, which also allows several conditional questions to fill up the same field (e.g. one list of amounts per periodicity). Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,11 @@ class SurveyUserInput(models.Model):
|
||||
)
|
||||
field_name: str = field_value.field_id.name
|
||||
|
||||
if value is None:
|
||||
# No value (e.g. question not displayed or skipped):
|
||||
# keep the default/computed value of the field, and
|
||||
# let another question fill up the same field.
|
||||
continue
|
||||
vals[field_name] = value
|
||||
|
||||
existing_record = self.find_existing_record(record_creation, vals)
|
||||
@@ -195,7 +200,7 @@ class SurveyUserInput(models.Model):
|
||||
if unique_fields:
|
||||
uniq_domain = []
|
||||
for uniq_field in unique_fields:
|
||||
uniq_domain.append((uniq_field, "=", vals[uniq_field]))
|
||||
uniq_domain.append((uniq_field, "=", vals.get(uniq_field, False)))
|
||||
duplicate = self.env[model].search(uniq_domain, limit=1)
|
||||
return duplicate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user