From 8dbf2e1ce4b770e9f9a5caf6bbfa08e31839164b Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Thu, 16 Feb 2023 16:11:40 +0000 Subject: [PATCH] [IMP] hr_attendance: input PIN using keyboard The kiosk's PIN mode was only accepting codes entered using the keyboard shown on screen, dismissing keys entered on a real keyboard. task-3127253 closes odoo/odoo#112922 Signed-off-by: Kevin Baptiste --- .../kiosk_confirm/kiosk_confirm.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/addons/hr_attendance/static/src/client_action/kiosk_confirm/kiosk_confirm.js b/addons/hr_attendance/static/src/client_action/kiosk_confirm/kiosk_confirm.js index 39fad9ac3f3..8a51f8f8e01 100644 --- a/addons/hr_attendance/static/src/client_action/kiosk_confirm/kiosk_confirm.js +++ b/addons/hr_attendance/static/src/client_action/kiosk_confirm/kiosk_confirm.js @@ -34,11 +34,40 @@ export class KioskConfirm extends Component { this.employeeHoursToday = registry.category("formatters").get("float_time")( employee_hours_today ); + onWillStart(this.onWillStart); } async onWillStart() { this.use_pin = await this.user.hasGroup("hr_attendance.group_hr_attendance_use_pin"); + + if (this.use_pin) { + browser.addEventListener('keydown', async (ev) => { + const allowedKeys = [...Array(10).keys()].reduce((acc, value) => { // { from '0': '0' ... to '9': '9' } + acc[value] = value; + return acc; + }, { + 'Delete': 'C', + 'Enter': 'OK', + 'Backspace': null, + }); + const key = ev.key; + + if (!Object.keys(allowedKeys).includes(key)) { + return; + } + + ev.preventDefault(); + ev.stopPropagation(); + + if (allowedKeys[key]) { + await this.onClickPadButton(allowedKeys[key]); + } + else { + this.state.codePin = this.state.codePin.substring(0, this.state.codePin.length - 1); + } + }); + } } onClickBack() {