From b1251b40d545659d50ff5ebfb6af430655e7b2cb Mon Sep 17 00:00:00 2001 From: David Beguin Date: Wed, 19 Sep 2018 15:19:57 +0200 Subject: [PATCH] [FIX] hr_attendance : fix kiosk mode quick multi scanning Since the the commit that added the barcode listener in the greeting_message view (aaff7d5d51e360f13c36363a2f118efb8ab163c8), if someone check in and check out and check in again quickly, during the 5 seconds before the welcome view come back, multiple rpc where made to call attendance_scan method, resulting to create inconsistent records in the db. Typically, a check in records could have been create before the confirmation of last check out. Here, we avoid scanning twice the same barcode, between welcome and greeting message view but also inside the greeting message view itself. Employees are now able to check in or check out quickly. Obviously, if the same employee wants to check in and check out within 5 sec, he will need to wait the 5 seconds. Task ID 1878251 Closes PR #27101 --- .../static/src/js/greeting_message.js | 42 +++++++++++++------ .../hr_attendance/static/src/js/kiosk_mode.js | 2 +- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/addons/hr_attendance/static/src/js/greeting_message.js b/addons/hr_attendance/static/src/js/greeting_message.js index a97564ae563..57191d0965b 100644 --- a/addons/hr_attendance/static/src/js/greeting_message.js +++ b/addons/hr_attendance/static/src/js/greeting_message.js @@ -5,6 +5,7 @@ var AbstractAction = require('web.AbstractAction'); var core = require('web.core'); var _t = core._t; +var previously_barcode_scanned; var GreetingMessage = AbstractAction.extend({ @@ -53,6 +54,20 @@ var GreetingMessage = AbstractAction.extend({ this.employee_name = action.employee_name; }, + willStart: function() { + if (this.attendance != undefined){ + this._rpc({ + model: 'hr.employee', + method: 'read', + args: [this.attendance.employee_id[0], ['barcode']], + }) + .then(function (employee) { + previously_barcode_scanned = employee[0].barcode; + }); + } + return this._super.apply(this, arguments); + }, + start: function() { if (this.attendance) { this.attendance.check_out ? this.farewell_message() : this.welcome_message(); @@ -139,18 +154,21 @@ var GreetingMessage = AbstractAction.extend({ if (this.return_to_main_menu) { // in case of multiple scans in the greeting message view, delete the timer, a new one will be created. clearTimeout(this.return_to_main_menu); } - this._rpc({ - model: 'hr.employee', - method: 'attendance_scan', - args: [barcode, ], - }) - .then(function (result) { - if (result.action) { - self.do_action(result.action); - } else if (result.warning) { - self.do_warn(result.warning); - } - }); + if (previously_barcode_scanned != barcode){ + previously_barcode_scanned = barcode; + this._rpc({ + model: 'hr.employee', + method: 'attendance_scan', + args: [barcode, ], + }) + .then(function (result) { + if (result.action) { + self.do_action(result.action); + } else if (result.warning) { + self.do_warn(result.warning); + } + }); + } }, destroy: function () { diff --git a/addons/hr_attendance/static/src/js/kiosk_mode.js b/addons/hr_attendance/static/src/js/kiosk_mode.js index 750fa43df47..361977717fe 100644 --- a/addons/hr_attendance/static/src/js/kiosk_mode.js +++ b/addons/hr_attendance/static/src/js/kiosk_mode.js @@ -36,6 +36,7 @@ var KioskMode = AbstractAction.extend({ _onBarcodeScanned: function(barcode) { var self = this; + core.bus.off('barcode_scanned', this, this._onBarcodeScanned); this._rpc({ model: 'hr.employee', method: 'attendance_scan', @@ -57,7 +58,6 @@ var KioskMode = AbstractAction.extend({ }, destroy: function () { - core.bus.off('barcode_scanned', this, this._onBarcodeScanned); clearInterval(this.clock_start); clearInterval(this._interval); this._super.apply(this, arguments);