-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IMP] sign_oca: Allow to store geolocalization #16
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}, | ||
Comment on lines
+69
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should prevent the error in the code by handling the possibility of geolocation not being available. For example:
|
||
}); | ||
this.props.trigger("history_back"); | ||
} | ||
_trigger_up(ev) { | ||
const evType = ev.name; | ||
const payload = ev.data; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,15 +40,20 @@ export class SignOcaPdfPortal extends SignOcaPdf { | |
super.postIframeFields(...arguments); | ||
this.checkFilledAll(); | ||
} | ||
_onClickSign() { | ||
async _onClickSign() { | ||
const position = await this.getLocation(); | ||
this.env.services | ||
.rpc({ | ||
route: | ||
"/sign_oca/sign/" + | ||
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, | ||
}, | ||
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should prevent the error in here as well |
||
}) | ||
.then((action) => { | ||
// As we are on frontend env, it is not possible to use do_action(), so we | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, in the
actions_sign
method, you could add a ValidationError if the template is marked asask_location
and the latitude and longitude are not provided.