[FIX] point_of_sale: scanning a product twice takes the barcode as the quantity of the product
- Connect a real barcode scanner. - Start a POS session. - Scan a product. The product appears in the list properly with a quantity at 1 - Scan the product again. Before this commit: After the second scan the quantity is the number represented by the barcode. The reason for this being that it's allowed to type a quantity with a numpad, but the scanner works pretty much like a keyboard. After this commit: Scanning a product multiple times just increase the quantity by one. But you can still type the quantity with a numpad, provided you don't type as fast as a barcode scanner. closes odoo/odoo#37530 Opw: 2075470 X-original-commit: db3ae61c00364894fef4684f34143f1cf575e882 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
committed by
fw-bot
parent
f7fd783eff
commit
472a12cc8e
@@ -1029,6 +1029,12 @@ var ActionButtonWidget = PosBaseWidget.extend({
|
||||
var ProductScreenWidget = ScreenWidget.extend({
|
||||
template:'ProductScreenWidget',
|
||||
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.timeout = null;
|
||||
this.buffered_key_events = [];
|
||||
},
|
||||
|
||||
start: function(){
|
||||
|
||||
var self = this;
|
||||
@@ -1098,11 +1104,40 @@ var ProductScreenWidget = ScreenWidget.extend({
|
||||
$(document).off('keydown.productscreen', this._onKeypadKeyDown);
|
||||
},
|
||||
|
||||
/**
|
||||
* Buffers the key typed and distinguishes between actual keystrokes and
|
||||
* scanner inputs.
|
||||
*
|
||||
* @private
|
||||
* @param {event} ev - The keyboard event.
|
||||
*/
|
||||
_onKeypadKeyDown: function (ev) {
|
||||
//prevent input and textarea keydown event
|
||||
if(!_.contains(["INPUT", "TEXTAREA"], $(ev.target).prop('tagName'))) {
|
||||
if ((ev.key >= "0" && ev.key <= "9") || ev.key === "."){
|
||||
this.numpad.state.appendNewChar(ev.key)
|
||||
clearTimeout(this.timeout);
|
||||
this.buffered_key_events.push(ev);
|
||||
this.timeout = setTimeout(_.bind(this._handleBufferedKeys, this), BarcodeEvents.max_time_between_keys_in_ms);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Processes the buffer of keys filled by _onKeypadKeyDown and
|
||||
* distinguishes between the actual keystrokes and scanner inputs.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_handleBufferedKeys: function () {
|
||||
// If more than 2 keys are recorded in the buffer, chances are high that the input comes
|
||||
// from a barcode scanner. In this case, we don't do anything.
|
||||
if (this.buffered_key_events.length > 2) {
|
||||
this.buffered_key_events = [];
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.buffered_key_events.length; ++i) {
|
||||
var ev = this.buffered_key_events[i];
|
||||
if ((ev.key >= "0" && ev.key <= "9") || ev.key === ".") {
|
||||
this.numpad.state.appendNewChar(ev.key);
|
||||
}
|
||||
else {
|
||||
switch (ev.key){
|
||||
@@ -1124,6 +1159,7 @@ var ProductScreenWidget = ScreenWidget.extend({
|
||||
}
|
||||
}
|
||||
}
|
||||
this.buffered_key_events = [];
|
||||
},
|
||||
});
|
||||
gui.define_screen({name:'products', widget: ProductScreenWidget});
|
||||
|
||||
Reference in New Issue
Block a user