Browse Source

[fix] scanner bug

pull/155/head
ufaks 9 years ago
committed by Vincent Van Rossem
parent
commit
b550159b3d
  1. 1
      pos_keyboard/__openerp__.py
  2. 73
      pos_keyboard/static/src/js/pos.js

1
pos_keyboard/__openerp__.py

@ -4,6 +4,7 @@
'author': "IT-Projects LLC, Ivan Yelizariev", 'author': "IT-Projects LLC, Ivan Yelizariev",
'license': 'LGPL-3', 'license': 'LGPL-3',
"website" : "https://yelizariev.github.io", "website" : "https://yelizariev.github.io",
'images': ['images/main.png'],
'category' : 'Point Of Sale', 'category' : 'Point Of Sale',
'version': '1.0.0', 'version': '1.0.0',
'depends': ['point_of_sale'], 'depends': ['point_of_sale'],

73
pos_keyboard/static/src/js/pos.js

@ -7,8 +7,8 @@ function pos_keyboard_widgets(instance, module){
res = resSuper.done(function(e){ res = resSuper.done(function(e){
self.pos.keypad.connect(); self.pos.keypad.connect();
self.pos.keypad.set_action_callback(function(data){ self.pos.keypad.set_action_callback(function(data){
self.keypad_action(data, self.pos.keypad.type);
});
self.keypad_action(data, self.pos.keypad.type);
});
}); });
return res; return res;
}, },
@ -39,11 +39,11 @@ function pos_keyboard_widgets(instance, module){
this.modeButton = { this.modeButton = {
qty: 'quantity', qty: 'quantity',
disc: 'discount', disc: 'discount',
price: 'price'
}
price: 'price'
}
} }
}); });
var PosModelSuper = module.PosModel; var PosModelSuper = module.PosModel;
module.PosModel = module.PosModel.extend({ module.PosModel = module.PosModel.extend({
initialize: function(session, attributes) { initialize: function(session, attributes) {
@ -52,15 +52,15 @@ function pos_keyboard_widgets(instance, module){
}, },
}); });
// this module mimics a keypad-only cash register. Use connect() and
// this module mimics a keypad-only cash register. Use connect() and
// disconnect() to activate and deactivate it. // disconnect() to activate and deactivate it.
module.Keypad = instance.web.Class.extend({ module.Keypad = instance.web.Class.extend({
init: function(attributes){ init: function(attributes){
this.pos = attributes.pos; this.pos = attributes.pos;
this.pos_widget = this.pos.pos_widget;
this.pos_widget = this.pos.pos_widget;
this.type = { this.type = {
numchar: 'number, dot', numchar: 'number, dot',
bmode: 'qty, disc, price',
bmode: 'qty, disc, price',
sign: '+, -', sign: '+, -',
backspace: 'backspace' backspace: 'backspace'
} }
@ -89,8 +89,8 @@ function pos_keyboard_widgets(instance, module){
reset_action_callback: function(){ reset_action_callback: function(){
this.action_callback = undefined; this.action_callback = undefined;
}, },
// starts catching keyboard events and tries to interpret keystrokes,
// starts catching keyboard events and tries to interpret keystrokes,
// calling the callback when needed. // calling the callback when needed.
connect: function(){ connect: function(){
var self = this; var self = this;
@ -105,7 +105,7 @@ function pos_keyboard_widgets(instance, module){
var KC_AMT_1 = 80; // KeyCode: Price (Keypad 'p') var KC_AMT_1 = 80; // KeyCode: Price (Keypad 'p')
var KC_DISC_1 = 68; // KeyCode: Discount Percentage [0..100] (Keypad 'd') var KC_DISC_1 = 68; // KeyCode: Discount Percentage [0..100] (Keypad 'd')
var KC_BACKSPACE = 8; // KeyCode: Backspace (Keypad 'backspace')
var KC_BACKSPACE = 8; // KeyCode: Backspace (Keypad 'backspace')
var kc_lookup = { var kc_lookup = {
48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4',
53: '5', 54: '6', 55: '7', 56: '8', 57: '9', 53: '5', 54: '6', 55: '7', 56: '8', 57: '9',
@ -117,7 +117,7 @@ function pos_keyboard_widgets(instance, module){
//cancel return to the previous page when press backspace //cancel return to the previous page when press backspace
var rx = /INPUT|SELECT|TEXTAREA/i; var rx = /INPUT|SELECT|TEXTAREA/i;
$(document).bind("keydown keypress", function(e){
$(document).on("keydown keypress", function(e){
if( e.which == 8 ){ // 8 == backspace if( e.which == 8 ){ // 8 == backspace
if(!rx.test(e.target.tagName) || e.target.disabled || e.target.readOnly ){ if(!rx.test(e.target.tagName) || e.target.disabled || e.target.readOnly ){
e.preventDefault(); e.preventDefault();
@ -126,53 +126,66 @@ function pos_keyboard_widgets(instance, module){
}); });
//usb keyboard keyup event //usb keyboard keyup event
$('body').delegate('','keyup', function (e){
var ok = false;
var timeStamp = 0;
$('body').on('keyup', '', function (e){
var statusHandler = !rx.test(e.target.tagName) || var statusHandler = !rx.test(e.target.tagName) ||
e.target.disabled || e.target.readOnly; e.target.disabled || e.target.readOnly;
if (statusHandler){ if (statusHandler){
var ok =false;
var is_number = false;
var type = self.type; var type = self.type;
var buttonMode = self.pos.pos_widget.numpad.modeButton
token = e.keyCode;
if ((token >= 96 && token <= 105 || token == 110) ||
var buttonMode = self.pos.pos_widget.numpad.modeButton;
var token = e.keyCode;
if ((token >= 96 && token <= 105 || token == 110) ||
(token >= 48 && token <= 57 || token == 190)) { (token >= 48 && token <= 57 || token == 190)) {
self.data.type = type.numchar; self.data.type = type.numchar;
self.data.val = kc_lookup[token]; self.data.val = kc_lookup[token];
is_number = true;
ok = true; ok = true;
}
}
else if (token == KC_PLU || token == KC_PLU_1) { else if (token == KC_PLU || token == KC_PLU_1) {
self.data.type = type.sign; self.data.type = type.sign;
ok = true; ok = true;
}
}
else if (token == KC_QTY || token == KC_QTY_1) { else if (token == KC_QTY || token == KC_QTY_1) {
self.data.type = type.bmode; self.data.type = type.bmode;
self.data.val = buttonMode.qty
self.data.val = buttonMode.qty;
ok = true; ok = true;
}
}
else if (token == KC_AMT || token == KC_AMT_1) { else if (token == KC_AMT || token == KC_AMT_1) {
self.data.type = type.bmode; self.data.type = type.bmode;
self.data.val = buttonMode.price; self.data.val = buttonMode.price;
ok = true; ok = true;
}
}
else if (token == KC_DISC || token == KC_DISC_1) { else if (token == KC_DISC || token == KC_DISC_1) {
self.data.type = type.bmode; self.data.type = type.bmode;
self.data.val = buttonMode.disc; self.data.val = buttonMode.disc;
ok = true; ok = true;
}
}
else if (token == KC_BACKSPACE) { else if (token == KC_BACKSPACE) {
self.data.type = type.backspace; self.data.type = type.backspace;
self.action_callback(self.data);
ok = true; ok = true;
}
if (ok) {self.action_callback(self.data);}
}
if (is_number) {
if (timeStamp + 50 > new Date().getTime()) {
ok = false;
}
}
timeStamp = new Date().getTime();
setTimeout(function(){
if (ok) {self.action_callback(self.data);}
}, 50);
} }
}); });
}, },
// stops catching keyboard events
// stops catching keyboard events
disconnect: function(){ disconnect: function(){
$('body').undelegate('', 'keyup')
},
$('body').off('keyup', '')
}
}); });
} }
@ -183,4 +196,4 @@ function pos_keyboard_widgets(instance, module){
var module = instance.point_of_sale; var module = instance.point_of_sale;
pos_keyboard_widgets(instance, module); pos_keyboard_widgets(instance, module);
} }
})()
})();
Loading…
Cancel
Save