[IMP] docuseal_signing: keep the Docuseal field order in the mapping

Fields are now ordered as returned by the Docuseal API: a sequence
field (reorderable with drag & drop) is written by
``action_fetch_fields`` according to the API field order, so deleting
a mapping line and re-fetching restores the original order instead of
appending it at the end.

Also refresh the French catalog (new Sequence field, new help texts,
stale smart_search entries dropped).

Covered by a unit test reproducing the delete-then-refetch scenario.

Assisted-By: GLM-5.3-Flash
This commit is contained in:
2026-11-03 16:45:43 +01:00
parent b3d0f4b0d3
commit 77d556c14a
6 changed files with 84 additions and 10 deletions

View File

@@ -41,7 +41,8 @@ class TestFetchFields(TransactionCase):
def test_fetch_fields_reconciles_mapping(self):
"""Existing mappings keep their partner field; removed Docuseal
fields are dropped and new ones are added."""
fields are dropped and new ones are added, in the order returned
by the Docuseal API."""
payload = {
"name": "Contract",
"submitters": [{"name": "Signer"}],
@@ -59,6 +60,12 @@ class TestFetchFields(TransactionCase):
}
self.assertEqual(names, {"phone", "extra"})
# The mapping order follows the Docuseal API field order.
self.assertEqual(
self.template.field_ids.mapped("docuseal_field_name"),
["phone", "extra"],
)
phone_mapping = self.template.field_ids.filtered(
lambda field: field.docuseal_field_name == "phone"
)
@@ -87,3 +94,39 @@ class TestFetchFields(TransactionCase):
self.assertEqual(self.template.name, "Contract")
self.assertEqual(self.template.submitter_role, "Counterparty")
self.assertFalse(self.template.field_ids)
def test_fetch_fields_restores_order_after_manual_delete(self):
"""Deleting the first mapped field then re-fetching from the
Docuseal API re-establishes the original field order."""
payload = {
"submitters": [{"name": "Signer"}],
"fields": [{"name": "a"}, {"name": "b"}, {"name": "c"}],
}
with mock.patch.object(
docuseal_template_module.urllib.request,
"urlopen",
return_value=self._mock_urlopen(payload),
):
self.template.action_fetch_fields()
self.assertEqual(
self.template.field_ids.mapped("docuseal_field_name"),
["a", "b", "c"],
)
# The user deletes the first mapping line.
self.template.field_ids[0].unlink()
# Re-fetching must restore the Docuseal order. Invalidate the
# one2many cache to read like a fresh request would (the web
# client always re-reads after the action).
with mock.patch.object(
docuseal_template_module.urllib.request,
"urlopen",
return_value=self._mock_urlopen(payload),
):
self.template.action_fetch_fields()
self.template.invalidate_recordset(["field_ids"])
self.assertEqual(
self.template.field_ids.mapped("docuseal_field_name"),
["a", "b", "c"],
)