[FIX] hr_attendance : fix kiosk mode quick multi scanning

Since the the commit that added the barcode listener in the
greeting_message view (aaff7d5d51),
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
This commit is contained in:
David Beguin
2018-09-20 10:09:02 +02:00
parent 6d141a1ab9
commit b1251b40d5
2 changed files with 31 additions and 13 deletions
@@ -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 () {
@@ -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);