From 9215ad7822ea7ffd6d2b73bb94e57bf790fc3b0b Mon Sep 17 00:00:00 2001 From: Quentin Mondot Date: Sun, 11 Oct 2026 21:03:03 +0200 Subject: [PATCH] [IMP] docuseal_signing : create draft submissions without sending the signature request _create_submissions gets a send_email parameter (default True, so the "Request signature" contextual action is unchanged), passed to the Docuseal API. It now returns the Docuseal response of each created submission (submitter id, slug, submission_id...) so callers can build a link to it. New _create_draft_submissions helper: creates pre-filled submissions with send_email=False, to be reviewed then sent for signature from Docuseal. Also adds help texts on template_id and submitter_role. Assisted-By: Claude Opus 5.5 --- docuseal_signing/models/docuseal_template.py | 33 ++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/docuseal_signing/models/docuseal_template.py b/docuseal_signing/models/docuseal_template.py index d82f220..eedbbc5 100644 --- a/docuseal_signing/models/docuseal_template.py +++ b/docuseal_signing/models/docuseal_template.py @@ -12,8 +12,15 @@ class DocusealTemplate(models.Model): _description = "Docuseal Template" name = fields.Char(string="Name") - template_id = fields.Integer(string="Template ID", required=True) - submitter_role = fields.Char(string="Submitter role") + template_id = fields.Integer( + string="Template ID", + help="You can find the template id in the URL when you have selected the template in Docuseal.", + required=True + ) + submitter_role = fields.Char( + string="Submitter role", + help="Name of the submitter role you have set up in Docuseal.", + ) field_ids = fields.One2many( comodel_name="docuseal.template.field", inverse_name="template_id", @@ -89,12 +96,18 @@ class DocusealTemplate(models.Model): self.server_action_id.unlink() self.server_action_id = False - def _create_submissions(self, partners): + def _create_draft_submissions(self, partners): + """Create pre-filled submissions without sending the signature request + email: the submission must then be sent from Docuseal.""" + return self._create_submissions(partners, send_email=False) + + def _create_submissions(self, partners, send_email=True): self.ensure_one() IrParam = self.env["ir.config_parameter"].sudo() api_token = IrParam.get_param("docuseal.api_token") api_url = IrParam.get_param("docuseal.api_url", "https://sign.elabore.coop") + results = [] for partner in partners: values = {} for field_map in self.field_ids: @@ -112,6 +125,7 @@ class DocusealTemplate(models.Model): payload = json.dumps({ "template_id": self.template_id, + "send_email": send_email, "submitters": [{ "name": partner.name, "role": self.submitter_role or "", @@ -121,9 +135,11 @@ class DocusealTemplate(models.Model): }).encode() _logger.info( - "Docuseal: sending submission for %s with template %s, values: %s", + "Docuseal: creating submission for %s with template %s " + "(send_email=%s), values: %s", partner.name, self.template_id, + send_email, values, ) req = urllib.request.Request( @@ -135,8 +151,7 @@ class DocusealTemplate(models.Model): }, ) with urllib.request.urlopen(req, timeout=10) as resp: - _logger.info( - "Docuseal submission created for %s: %s", - partner.name, - resp.read().decode(), - ) + body = resp.read().decode() + _logger.info("Docuseal submission created for %s: %s", partner.name, body) + results.append(json.loads(body)) + return results