| 1 |
import { Component } from "@odoo/owl"; |
| 2 |
import { useService } from "@web/core/utils/hooks"; |
| 3 |
import { useDebounced } from "@web/core/utils/timing"; |
| 4 |
|
| 5 |
export class CheckInOut extends Component { |
| 6 |
static template = "hr_attendance.CheckInOut"; |
| 7 |
static props = { |
| 8 |
checkedIn: Boolean, |
| 9 |
employeeId: Number, |
| 10 |
nextAction: String, |
| 11 |
}; |
| 12 |
|
| 13 |
setup() { |
| 14 |
this.actionService = useService("action"); |
| 15 |
this.orm = useService("orm"); |
| 16 |
this.notification = useService("notification"); |
| 17 |
|
| 18 |
this.onClickSignInOut = useDebounced(this.signInOut, 200, { immediate: true }); |
| 19 |
} |
| 20 |
|
| 21 |
async signInOut() { |
| 22 |
navigator.geolocation.getCurrentPosition( |
| 23 |
({coords: {latitude, longitude}}) => { |
| 24 |
this.orm.call("hr.employee", "update_last_position", [ |
| 25 |
[this.props.employeeId], |
| 26 |
latitude, |
| 27 |
longitude |
| 28 |
]) |
| 29 |
}, |
| 30 |
err => { |
| 31 |
this.orm.call("hr.employee", "update_last_position", [ |
| 32 |
[this.props.employeeId], |
| 33 |
false, |
| 34 |
false |
| 35 |
]) |
| 36 |
}) |
| 37 |
const result = await this.orm.call("hr.employee", "attendance_manual", [ |
| 38 |
[this.props.employeeId], |
| 39 |
this.props.nextAction, |
| 40 |
]); |
| 41 |
if (result.action) { |
| 42 |
this.actionService.doAction(result.action); |
| 43 |
} else if (result.warning) { |
| 44 |
this.notification.add(result.warning, {type: "danger"}); |
| 45 |
} |
| 46 |
} |
| 47 |
} |