[IMP] survey_record_generation : new option update_existing_fields

This commit is contained in:
2026-04-09 09:42:36 +02:00
parent 0d1866ace3
commit 33280626db
5 changed files with 113 additions and 16 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_fields = fields.Boolean(
string="Update existing fields",
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_fields:
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: