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