[FIX] docuseal_signing: keep partner field mappings on fields fetch
``action_fetch_fields`` wiped the whole ``field_ids`` mapping on every fetch, dropping the res.partner fields configured by the administrator. Reconcile instead: keep existing mappings untouched, add fields new to the Docuseal template and drop the ones removed from it. Covered by unit tests running against a mocked Docuseal API. Assisted-By: GLM-5.3-Flash
This commit is contained in:
@@ -51,14 +51,23 @@ class DocusealTemplate(models.Model):
|
||||
if data.get("submitters") and not self.submitter_role:
|
||||
self.submitter_role = data["submitters"][0].get("name", "")
|
||||
|
||||
self.field_ids.unlink()
|
||||
fields_data = [
|
||||
{"template_id": self.id, "docuseal_field_name": f["name"]}
|
||||
for f in data.get("fields", [])
|
||||
if f.get("name")
|
||||
# Reconcile the field mapping with the Docuseal template instead of
|
||||
# wiping it: existing mappings keep their res.partner field.
|
||||
existing = {
|
||||
field.docuseal_field_name: field for field in self.field_ids
|
||||
}
|
||||
docuseal_names = [
|
||||
f["name"] for f in data.get("fields", []) if f.get("name")
|
||||
]
|
||||
if fields_data:
|
||||
self.env["docuseal.template.field"].create(fields_data)
|
||||
for name in docuseal_names:
|
||||
if name not in existing:
|
||||
self.env["docuseal.template.field"].create({
|
||||
"template_id": self.id,
|
||||
"docuseal_field_name": name,
|
||||
})
|
||||
self.field_ids.filtered(
|
||||
lambda field: field.docuseal_field_name not in docuseal_names
|
||||
).unlink()
|
||||
|
||||
def action_create_server_action(self):
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user