diff --git a/docuseal_signing/README.md b/docuseal_signing/README.md index db9a4fb..95c5b66 100644 --- a/docuseal_signing/README.md +++ b/docuseal_signing/README.md @@ -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 diff --git a/docuseal_signing/i18n/fr.po b/docuseal_signing/i18n/fr.po index a762dec..5b93c1e 100644 --- a/docuseal_signing/i18n/fr.po +++ b/docuseal_signing/i18n/fr.po @@ -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" diff --git a/docuseal_signing/models/docuseal_template.py b/docuseal_signing/models/docuseal_template.py index 7618991..9ca6c03 100644 --- a/docuseal_signing/models/docuseal_template.py +++ b/docuseal_signing/models/docuseal_template.py @@ -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 diff --git a/docuseal_signing/models/docuseal_template_field.py b/docuseal_signing/models/docuseal_template_field.py index 8859264..031ab79 100644 --- a/docuseal_signing/models/docuseal_template_field.py +++ b/docuseal_signing/models/docuseal_template_field.py @@ -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", diff --git a/docuseal_signing/tests/test_fetch_fields.py b/docuseal_signing/tests/test_fetch_fields.py index 853257e..e68a93f 100644 --- a/docuseal_signing/tests/test_fetch_fields.py +++ b/docuseal_signing/tests/test_fetch_fields.py @@ -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"], + ) diff --git a/docuseal_signing/views/docuseal_template_views.xml b/docuseal_signing/views/docuseal_template_views.xml index 2efb849..81db6ed 100644 --- a/docuseal_signing/views/docuseal_template_views.xml +++ b/docuseal_signing/views/docuseal_template_views.xml @@ -53,6 +53,7 @@ +