[IMP] survey_record_generation : new option update_existing_fields
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m32s

This commit is contained in:
2026-04-09 09:42:36 +02:00
parent 0d1866ace3
commit aff1a6caae
7 changed files with 139 additions and 61 deletions

View File

@@ -27,6 +27,11 @@ class SurveyRecordCreation(models.Model):
help="Choose the field you want to use to retrieve the existing record. "
"WARNING: We update only the first record found.",
)
update_existing_values = fields.Boolean(
string="Update existing values",
help="The default behavior is to not update the existing fields. "
"If checked, the existing fields will be updated. ",
)
allowed_field_ids = fields.Many2many(
"ir.model.fields",
compute="_compute_allowed_field_ids",

View File

@@ -71,12 +71,15 @@ class SurveyUserInput(models.Model):
if duplicate:
record = duplicate
elif existing_record:
vals_with_keys_not_in_record = {
k: v
for k, v in vals.items()
if not getattr(existing_record, k, False)
}
existing_record.write(vals_with_keys_not_in_record)
if record_creation.update_existing_values:
existing_record.write(vals)
else:
vals_with_keys_not_in_record = {
k: v
for k, v in vals.items()
if not getattr(existing_record, k, False)
}
existing_record.write(vals_with_keys_not_in_record)
record = existing_record
else:
try: