[IMP] survey_record_generation : new option update_existing_fields
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m32s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m32s
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user