diff --git a/sign_oca/controllers/main.py b/sign_oca/controllers/main.py index cbfd94de..45033a7c 100644 --- a/sign_oca/controllers/main.py +++ b/sign_oca/controllers/main.py @@ -92,11 +92,15 @@ def get_sign_oca_info_access(self, signer_id, access_token): auth="public", website=True, ) - def get_sign_oca_sign_access(self, signer_id, access_token, items): + def get_sign_oca_sign_access( + self, signer_id, access_token, items, latitude=False, longitude=False + ): try: signer_sudo = self._document_check_access( "sign.oca.request.signer", signer_id, access_token ) except (AccessError, MissingError): return request.redirect("/my") - return signer_sudo.action_sign(items, access_token=access_token) + return signer_sudo.action_sign( + items, access_token=access_token, latitude=latitude, longitude=longitude + ) diff --git a/sign_oca/models/sign_oca_request.py b/sign_oca/models/sign_oca_request.py index 910b28b7..278ce377 100644 --- a/sign_oca/models/sign_oca_request.py +++ b/sign_oca/models/sign_oca_request.py @@ -96,6 +96,7 @@ class SignOcaRequest(models.Model): states={"draft": [("readonly", False)]}, ) next_item_id = fields.Integer(compute="_compute_next_item_id") + ask_location = fields.Boolean() @api.depends("signer_ids") @api.depends_context("uid") @@ -368,6 +369,8 @@ class SignOcaRequestSigner(models.Model): "ir.sequence", copy=False, default=lambda r: r._get_sequence() ) altered_hash = fields.Boolean(compute="_compute_altered_hash") + latitude = fields.Float() + longitude = fields.Float() @api.depends("request_id.record_ref") def _compute_model(self): @@ -412,6 +415,7 @@ def get_info(self, access_token=False): "name": self.request_id.template_id.name, "items": self.request_id.signatory_data, "to_sign": self.request_id.to_sign, + "ask_location": self.request_id.ask_location, "partner": { "id": self.partner_id.id, "name": self.partner_id.name, @@ -430,7 +434,7 @@ def sign(self): "url": self.access_url, } - def action_sign(self, items, access_token=False): + def action_sign(self, items, access_token=False, latitude=False, longitude=False): self.ensure_one() if self.signed_on: raise ValidationError( @@ -475,6 +479,8 @@ def action_sign(self, items, access_token=False): } ) self.signature_hash = final_hash + self.latitude = latitude + self.longitude = longitude self.request_id._check_signed() self._set_action_log("sign", access_token=access_token) if self.sequence_id: diff --git a/sign_oca/models/sign_oca_template.py b/sign_oca/models/sign_oca_template.py index 611e6fa2..860a84ec 100644 --- a/sign_oca/models/sign_oca_template.py +++ b/sign_oca/models/sign_oca_template.py @@ -12,6 +12,7 @@ class SignOcaTemplate(models.Model): name = fields.Char(required=True) data = fields.Binary(attachment=True, required=True) + ask_location = fields.Boolean() filename = fields.Char() item_ids = fields.One2many("sign.oca.template.item", inverse_name="template_id") request_count = fields.Integer(compute="_compute_request_count") diff --git a/sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.esm.js b/sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.esm.js index 1a0f1de4..0b3599ff 100644 --- a/sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.esm.js +++ b/sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.esm.js @@ -28,18 +28,51 @@ export default class SignOcaPdf extends SignOcaPdfCommon { }) ); $buttons.on("click.o_sign_oca_button_sign", () => { - this.env.services - .rpc({ - model: this.props.model, - method: "action_sign", - args: [[this.props.res_id], this.info.items], - }) - .then(() => { - this.props.trigger("history_back"); - }); + this.signOca(); }); return $buttons; } + async getLocation() { + if (!this.info.ask_location || !navigator.geolocation) { + return {}; + } + try { + return await new Promise((resolve, reject) => { + navigator.geolocation.getCurrentPosition(resolve, reject); + }); + + // Do something with the latitude and longitude + } catch (error) { + switch (error.code) { + case error.PERMISSION_DENIED: + console.error("User denied the request for geolocation."); + break; + case error.POSITION_UNAVAILABLE: + console.error("Location information is unavailable."); + break; + case error.TIMEOUT: + console.error("The request to get user location timed out."); + break; + default: + console.error("An unknown error occurred."); + break; + } + } + return {}; + } + async signOca() { + const position = await this.getLocation(); + await this.env.services.rpc({ + model: this.props.model, + method: "action_sign", + args: [[this.props.res_id], this.info.items], + kwargs: { + latitude: position.coords.latitude, + longitude: position.coords.longitude, + }, + }); + this.props.trigger("history_back"); + } _trigger_up(ev) { const evType = ev.name; const payload = ev.data; diff --git a/sign_oca/static/src/components/sign_oca_pdf_portal/sign_oca_pdf_portal.esm.js b/sign_oca/static/src/components/sign_oca_pdf_portal/sign_oca_pdf_portal.esm.js index 3b0c2cf3..79230fcf 100644 --- a/sign_oca/static/src/components/sign_oca_pdf_portal/sign_oca_pdf_portal.esm.js +++ b/sign_oca/static/src/components/sign_oca_pdf_portal/sign_oca_pdf_portal.esm.js @@ -40,7 +40,8 @@ export class SignOcaPdfPortal extends SignOcaPdf { super.postIframeFields(...arguments); this.checkFilledAll(); } - _onClickSign() { + async _onClickSign() { + const position = await this.getLocation(); this.env.services .rpc({ route: @@ -48,7 +49,11 @@ export class SignOcaPdfPortal extends SignOcaPdf { this.props.signer_id + "/" + this.props.access_token, - params: {items: this.info.items}, + params: { + items: this.info.items, + latitude: position.coords.latitude, + longitude: position.coords.longitude, + }, }) .then((action) => { // As we are on frontend env, it is not possible to use do_action(), so we diff --git a/sign_oca/views/sign_oca_request.xml b/sign_oca/views/sign_oca_request.xml index b89a6eae..a0fe2405 100644 --- a/sign_oca/views/sign_oca_request.xml +++ b/sign_oca/views/sign_oca_request.xml @@ -355,6 +355,8 @@ + + diff --git a/sign_oca/views/sign_oca_template.xml b/sign_oca/views/sign_oca_template.xml index 658bf6a1..2d235740 100644 --- a/sign_oca/views/sign_oca_template.xml +++ b/sign_oca/views/sign_oca_template.xml @@ -43,6 +43,7 @@ + diff --git a/sign_oca/wizards/sign_oca_template_generate.py b/sign_oca/wizards/sign_oca_template_generate.py index 5eaa2c0b..cb5311b9 100644 --- a/sign_oca/wizards/sign_oca_template_generate.py +++ b/sign_oca/wizards/sign_oca_template_generate.py @@ -32,6 +32,7 @@ def _generate_vals(self): "template_id": self.template_id.id, "signatory_data": self.template_id._get_signatory_data(), "data": self.template_id.data, + "ask_location": self.template_id.ask_location, "signer_ids": [ ( 0,