[ADD] docuseal_signing: request Docuseal signatures from Odoo #1
@@ -12,8 +12,15 @@ class DocusealTemplate(models.Model):
|
|||||||
_description = "Docuseal Template"
|
_description = "Docuseal Template"
|
||||||
|
|
||||||
name = fields.Char(string="Name")
|
name = fields.Char(string="Name")
|
||||||
template_id = fields.Integer(string="Template ID", required=True)
|
template_id = fields.Integer(
|
||||||
submitter_role = fields.Char(string="Submitter role")
|
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(
|
field_ids = fields.One2many(
|
||||||
comodel_name="docuseal.template.field",
|
comodel_name="docuseal.template.field",
|
||||||
inverse_name="template_id",
|
inverse_name="template_id",
|
||||||
@@ -89,12 +96,18 @@ class DocusealTemplate(models.Model):
|
|||||||
self.server_action_id.unlink()
|
self.server_action_id.unlink()
|
||||||
self.server_action_id = False
|
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()
|
self.ensure_one()
|
||||||
IrParam = self.env["ir.config_parameter"].sudo()
|
IrParam = self.env["ir.config_parameter"].sudo()
|
||||||
api_token = IrParam.get_param("docuseal.api_token")
|
api_token = IrParam.get_param("docuseal.api_token")
|
||||||
api_url = IrParam.get_param("docuseal.api_url", "https://sign.elabore.coop")
|
api_url = IrParam.get_param("docuseal.api_url", "https://sign.elabore.coop")
|
||||||
|
|
||||||
|
results = []
|
||||||
for partner in partners:
|
for partner in partners:
|
||||||
values = {}
|
values = {}
|
||||||
for field_map in self.field_ids:
|
for field_map in self.field_ids:
|
||||||
@@ -112,6 +125,7 @@ class DocusealTemplate(models.Model):
|
|||||||
|
|
||||||
payload = json.dumps({
|
payload = json.dumps({
|
||||||
"template_id": self.template_id,
|
"template_id": self.template_id,
|
||||||
|
"send_email": send_email,
|
||||||
"submitters": [{
|
"submitters": [{
|
||||||
"name": partner.name,
|
"name": partner.name,
|
||||||
"role": self.submitter_role or "",
|
"role": self.submitter_role or "",
|
||||||
@@ -121,9 +135,11 @@ class DocusealTemplate(models.Model):
|
|||||||
}).encode()
|
}).encode()
|
||||||
|
|
||||||
_logger.info(
|
_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,
|
partner.name,
|
||||||
self.template_id,
|
self.template_id,
|
||||||
|
send_email,
|
||||||
values,
|
values,
|
||||||
)
|
)
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
@@ -135,8 +151,7 @@ class DocusealTemplate(models.Model):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||||
_logger.info(
|
body = resp.read().decode()
|
||||||
"Docuseal submission created for %s: %s",
|
_logger.info("Docuseal submission created for %s: %s", partner.name, body)
|
||||||
partner.name,
|
results.append(json.loads(body))
|
||||||
resp.read().decode(),
|
return results
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user