[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:
@@ -11,9 +11,10 @@ signatures from partners in a few clicks.
|
||||
templates by their ID and submitter role, and fetch their field list
|
||||
from the Docuseal API with a single click.
|
||||
- **Field mapping** (`docuseal.template.field`): map each Docuseal
|
||||
field to a `res.partner` field. Values are pre-filled at submission
|
||||
time and locked so the signer cannot change them (empty mappings stay
|
||||
editable by the signer).
|
||||
field to a `res.partner` field. Fields are kept in the order returned
|
||||
by the Docuseal API (reorderable with drag & drop). Values are
|
||||
pre-filled at submission time and locked so the signer cannot change
|
||||
them (empty mappings stay editable by the signer).
|
||||
- **One-click signature request**: generate a server action bound to
|
||||
`res.partner` (contextual *Action* menu entry) that creates a Docuseal
|
||||
submission for the selected contacts and emails them the signature
|
||||
|
||||
@@ -6,8 +6,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 18.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-05-19 16:22+0000\n"
|
||||
"PO-Revision-Date: 2026-05-19 16:22+0000\n"
|
||||
"POT-Creation-Date: 2026-11-03 15:44+0000\n"
|
||||
"PO-Revision-Date: 2026-11-03 15:44+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -70,7 +70,9 @@ msgstr "Créé le"
|
||||
#. module: docuseal_signing
|
||||
#: model_terms:ir.ui.view,arch_db:docuseal_signing.res_config_settings_view_form_docuseal
|
||||
msgid "Define field mappings and generate contextual actions on contacts"
|
||||
msgstr "Définir les correspondances de champs et générer les actions contextuelles sur les contacts"
|
||||
msgstr ""
|
||||
"Définir les correspondances de champs et générer les actions contextuelles "
|
||||
"sur les contacts"
|
||||
|
||||
#. module: docuseal_signing
|
||||
#: model_terms:ir.ui.view,arch_db:docuseal_signing.docuseal_template_view_form
|
||||
@@ -177,6 +179,16 @@ msgstr "Gérer les templates Docuseal"
|
||||
msgid "Name"
|
||||
msgstr "Nom"
|
||||
|
||||
#. module: docuseal_signing
|
||||
#: model:ir.model.fields,help:docuseal_signing.field_docuseal_template__submitter_role
|
||||
msgid "Name of the submitter role you have set up in Docuseal."
|
||||
msgstr "Nom du rôle de signataire défini dans Docuseal."
|
||||
|
||||
#. module: docuseal_signing
|
||||
#: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template_field__sequence
|
||||
msgid "Sequence"
|
||||
msgstr "Séquence"
|
||||
|
||||
#. module: docuseal_signing
|
||||
#: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template__server_action_id
|
||||
msgid "Server action"
|
||||
@@ -204,6 +216,15 @@ msgstr "Template"
|
||||
msgid "Template ID"
|
||||
msgstr "ID du template"
|
||||
|
||||
#. module: docuseal_signing
|
||||
#: model:ir.model.fields,help:docuseal_signing.field_docuseal_template__template_id
|
||||
msgid ""
|
||||
"You can find the template id in the URL when you have selected the template "
|
||||
"in Docuseal."
|
||||
msgstr ""
|
||||
"Vous trouverez l'identifiant du template dans l'URL après avoir sélectionné "
|
||||
"le template dans Docuseal."
|
||||
|
||||
#. module: docuseal_signing
|
||||
#: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template_field__partner_field_id
|
||||
msgid "res.partner field"
|
||||
|
||||
@@ -52,18 +52,23 @@ class DocusealTemplate(models.Model):
|
||||
self.submitter_role = data["submitters"][0].get("name", "")
|
||||
|
||||
# Reconcile the field mapping with the Docuseal template instead of
|
||||
# wiping it: existing mappings keep their res.partner field.
|
||||
# wiping it: existing mappings keep their res.partner field and the
|
||||
# sequence follows the field order returned by the Docuseal API.
|
||||
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")
|
||||
]
|
||||
for name in docuseal_names:
|
||||
if name not in existing:
|
||||
for index, name in enumerate(docuseal_names):
|
||||
field = existing.get(name)
|
||||
if field:
|
||||
field.sequence = index
|
||||
else:
|
||||
self.env["docuseal.template.field"].create({
|
||||
"template_id": self.id,
|
||||
"docuseal_field_name": name,
|
||||
"sequence": index,
|
||||
})
|
||||
self.field_ids.filtered(
|
||||
lambda field: field.docuseal_field_name not in docuseal_names
|
||||
|
||||
@@ -4,6 +4,9 @@ from odoo import fields, models
|
||||
class DocusealTemplateField(models.Model):
|
||||
_name = "docuseal.template.field"
|
||||
_description = "Docuseal Template Field"
|
||||
_order = "sequence, id"
|
||||
|
||||
sequence = fields.Integer(default=10)
|
||||
|
||||
template_id = fields.Many2one(
|
||||
comodel_name="docuseal.template",
|
||||
|
||||
@@ -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"],
|
||||
)
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
</div>
|
||||
<field name="field_ids" string="Field mapping">
|
||||
<list editable="bottom">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="docuseal_field_name" readonly="1"/>
|
||||
<field
|
||||
name="partner_field_id"
|
||||
|
||||
Reference in New Issue
Block a user