[ADD] docuseal_signing: request Docuseal signatures from Odoo #1

Open
mondot wants to merge 15 commits from docuseal_signing into 18.0
6 changed files with 84 additions and 10 deletions
Showing only changes of commit 77d556c14a - Show all commits

View File

@@ -11,9 +11,10 @@ signatures from partners in a few clicks.
templates by their ID and submitter role, and fetch their field list templates by their ID and submitter role, and fetch their field list
from the Docuseal API with a single click. from the Docuseal API with a single click.
- **Field mapping** (`docuseal.template.field`): map each Docuseal - **Field mapping** (`docuseal.template.field`): map each Docuseal
field to a `res.partner` field. Values are pre-filled at submission field to a `res.partner` field. Fields are kept in the order returned
time and locked so the signer cannot change them (empty mappings stay by the Docuseal API (reorderable with drag & drop). Values are
editable by the signer). 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 - **One-click signature request**: generate a server action bound to
`res.partner` (contextual *Action* menu entry) that creates a Docuseal `res.partner` (contextual *Action* menu entry) that creates a Docuseal
submission for the selected contacts and emails them the signature submission for the selected contacts and emails them the signature

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 18.0\n" "Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-05-19 16:22+0000\n" "POT-Creation-Date: 2026-11-03 15:44+0000\n"
"PO-Revision-Date: 2026-05-19 16:22+0000\n" "PO-Revision-Date: 2026-11-03 15:44+0000\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@@ -70,7 +70,9 @@ msgstr "Créé le"
#. module: docuseal_signing #. module: docuseal_signing
#: model_terms:ir.ui.view,arch_db:docuseal_signing.res_config_settings_view_form_docuseal #: 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" 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 #. module: docuseal_signing
#: model_terms:ir.ui.view,arch_db:docuseal_signing.docuseal_template_view_form #: 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" msgid "Name"
msgstr "Nom" 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 #. module: docuseal_signing
#: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template__server_action_id #: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template__server_action_id
msgid "Server action" msgid "Server action"
@@ -204,6 +216,15 @@ msgstr "Template"
msgid "Template ID" msgid "Template ID"
msgstr "ID du template" 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 #. module: docuseal_signing
#: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template_field__partner_field_id #: model:ir.model.fields,field_description:docuseal_signing.field_docuseal_template_field__partner_field_id
msgid "res.partner field" msgid "res.partner field"

View File

@@ -52,18 +52,23 @@ class DocusealTemplate(models.Model):
self.submitter_role = data["submitters"][0].get("name", "") self.submitter_role = data["submitters"][0].get("name", "")
# Reconcile the field mapping with the Docuseal template instead of # 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 = { existing = {
field.docuseal_field_name: field for field in self.field_ids field.docuseal_field_name: field for field in self.field_ids
} }
docuseal_names = [ docuseal_names = [
f["name"] for f in data.get("fields", []) if f.get("name") f["name"] for f in data.get("fields", []) if f.get("name")
] ]
for name in docuseal_names: for index, name in enumerate(docuseal_names):
if name not in existing: field = existing.get(name)
if field:
field.sequence = index
else:
self.env["docuseal.template.field"].create({ self.env["docuseal.template.field"].create({
"template_id": self.id, "template_id": self.id,
"docuseal_field_name": name, "docuseal_field_name": name,
"sequence": index,
}) })
self.field_ids.filtered( self.field_ids.filtered(
lambda field: field.docuseal_field_name not in docuseal_names lambda field: field.docuseal_field_name not in docuseal_names

View File

@@ -4,6 +4,9 @@ from odoo import fields, models
class DocusealTemplateField(models.Model): class DocusealTemplateField(models.Model):
_name = "docuseal.template.field" _name = "docuseal.template.field"
_description = "Docuseal Template Field" _description = "Docuseal Template Field"
_order = "sequence, id"
sequence = fields.Integer(default=10)
template_id = fields.Many2one( template_id = fields.Many2one(
comodel_name="docuseal.template", comodel_name="docuseal.template",

View File

@@ -41,7 +41,8 @@ class TestFetchFields(TransactionCase):
def test_fetch_fields_reconciles_mapping(self): def test_fetch_fields_reconciles_mapping(self):
"""Existing mappings keep their partner field; removed Docuseal """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 = { payload = {
"name": "Contract", "name": "Contract",
"submitters": [{"name": "Signer"}], "submitters": [{"name": "Signer"}],
@@ -59,6 +60,12 @@ class TestFetchFields(TransactionCase):
} }
self.assertEqual(names, {"phone", "extra"}) 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( phone_mapping = self.template.field_ids.filtered(
lambda field: field.docuseal_field_name == "phone" lambda field: field.docuseal_field_name == "phone"
) )
@@ -87,3 +94,39 @@ class TestFetchFields(TransactionCase):
self.assertEqual(self.template.name, "Contract") self.assertEqual(self.template.name, "Contract")
self.assertEqual(self.template.submitter_role, "Counterparty") self.assertEqual(self.template.submitter_role, "Counterparty")
self.assertFalse(self.template.field_ids) 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"],
)

View File

@@ -53,6 +53,7 @@
</div> </div>
<field name="field_ids" string="Field mapping"> <field name="field_ids" string="Field mapping">
<list editable="bottom"> <list editable="bottom">
<field name="sequence" widget="handle"/>
<field name="docuseal_field_name" readonly="1"/> <field name="docuseal_field_name" readonly="1"/>
<field <field
name="partner_field_id" name="partner_field_id"