diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index a6886c08ae1..6f2e65654f0 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2717,6 +2717,22 @@ exports.NumpadState = Backbone.Model.extend({ }); this.trigger('set_value',this.get('buffer')); }, + positiveSign: function() { + var oldBuffer; + oldBuffer = this.get('buffer'); + if (oldBuffer[0] === '-'){ + this.set({buffer: oldBuffer.substr(1)}); + this.trigger('set_value',this.get('buffer')); + } + }, + negativeSign: function() { + var oldBuffer; + oldBuffer = this.get('buffer'); + if (oldBuffer[0] !== '-'){ + this.set({buffer: "-" + oldBuffer}); + this.trigger('set_value',this.get('buffer')); + } + }, changeMode: function(newMode) { this.set({ buffer: "0", @@ -2730,7 +2746,13 @@ exports.NumpadState = Backbone.Model.extend({ }); }, resetValue: function(){ - this.set({buffer:'0'}); + if(this.get('buffer') === "") { + this.trigger('set_value','remove'); + } + else { + this.set({ buffer: "" }); + this.trigger('set_value',this.get('buffer')); + } }, }); diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index 4bf06abdc6b..d13cdc2f9fd 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -1016,6 +1016,7 @@ var ProductScreenWidget = ScreenWidget.extend({ if (this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard) { this.chrome.widget.keyboard.connect($(this.el.querySelector('.searchbox input'))); } + $(document).on('keydown.productscreen',this._onKeypadKeyDown.bind(this)); }, close: function(){ @@ -1023,6 +1024,35 @@ var ProductScreenWidget = ScreenWidget.extend({ if(this.pos.config.iface_vkeyboard && this.chrome.widget.keyboard){ this.chrome.widget.keyboard.hide(); } + $(document).off('keydown.productscreen',this._onKeypadKeyDown.bind(this)); + }, + + _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) + } + else { + switch (ev.key){ + case "Backspace": + this.numpad.state.deleteLastChar(); + break; + case "Delete": + this.numpad.state.resetValue(); + break; + case ",": + this.numpad.state.appendNewChar("."); + break; + case "+": + this.numpad.state.positiveSign(); + break; + case "-": + this.numpad.state.negativeSign(); + break; + } + } + } }, }); gui.define_screen({name:'products', widget: ProductScreenWidget});