From 60b17e760c594f4d4b9ffad86e5d002267bdc4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 20 Sep 2013 11:47:34 +0200 Subject: [PATCH 1/3] [IMP] point_of_sale: when the product search returns only one product, order it on 'enter' keypress bzr revid: fva@openerp.com-20130920094734-mvte0wkdw151691n --- .../static/src/js/widget_keyboard.js | 13 +++++-- addons/point_of_sale/static/src/js/widgets.js | 38 ++++++++++++------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/addons/point_of_sale/static/src/js/widget_keyboard.js b/addons/point_of_sale/static/src/js/widget_keyboard.js index 05ccdd78ca6..22245b31227 100644 --- a/addons/point_of_sale/static/src/js/widget_keyboard.js +++ b/addons/point_of_sale/static/src/js/widget_keyboard.js @@ -43,10 +43,15 @@ function openerp_pos_keyboard(instance, module){ //module is instance.point_of_s // Write a character to the input zone writeCharacter: function(character){ - var $input = this.$target - $input[0].value += character; - $input.keydown(); - $input.keyup(); + var $input = this.$target; + if(character === '\n'){ + $input.trigger($.Event('keydown',{which:13})); + $input.trigger($.Event('keyup',{which:13})); + }else{ + $input[0].value += character; + $input.keydown(); + $input.keyup(); + } }, // Sends a 'return' character to the input zone. TODO diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index 0768791651b..e36161e289f 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -516,7 +516,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa var cat = self.pos.db.get_category_by_id(id); self.set_category(cat); self.renderElement(); - self.search_and_categories(cat); }); }); // breadcrumb click actions @@ -525,12 +524,13 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa var category = self.pos.db.get_category_by_id(id); self.set_category(category); self.renderElement(); - self.search_and_categories(category); }); + + this.search_and_categories(); + if(this.pos.iface_vkeyboard && this.pos_widget.onscreen_keyboard){ this.pos_widget.onscreen_keyboard.connect(this.$('.searchbox input')); } - this.search_and_categories(); }, set_product_type: function(type){ // 'all' | 'weightable' @@ -542,7 +542,14 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa reset_category: function(){ this.set_category(); this.renderElement(); - this.search_and_categories(); + }, + + // empties the content of the search box + clear_search: function(){ + var products = this.pos.db.get_product_by_category(this.category.id); + this.pos.get('products').reset(products); + this.$('.searchbox input').val('').focus(); + this.$('.search-clear').fadeOut(); }, // filters the products, and sets up the search callbacks @@ -554,12 +561,20 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa self.pos.get('products').reset(products); // filter the products according to the search string - this.$('.searchbox input').keyup(function(){ + this.$('.searchbox input').keyup(function(event){ + console.log('event',event); query = $(this).val().toLowerCase(); if(query){ - var products = self.pos.db.search_product_in_category(self.category.id, query); - self.pos.get('products').reset(products); - self.$('.search-clear').fadeIn(); + if(event.which === 13){ + if( self.pos.get('products').size() === 1 ){ + self.pos.get('selectedOrder').addProduct(self.pos.get('products').at(0)); + self.clear_search(); + } + }else{ + var products = self.pos.db.search_product_in_category(self.category.id, query); + self.pos.get('products').reset(products); + self.$('.search-clear').fadeIn(); + } }else{ var products = self.pos.db.get_product_by_category(self.category.id); self.pos.get('products').reset(products); @@ -567,14 +582,9 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa } }); - this.$('.searchbox input').click(function(){}); //Why ??? - //reset the search when clicking on reset this.$('.search-clear').click(function(){ - var products = self.pos.db.get_product_by_category(self.category.id); - self.pos.get('products').reset(products); - self.$('.searchbox input').val('').focus(); - self.$('.search-clear').fadeOut(); + self.clear_search(); }); }, }); From 885bd7ff7a9e3d55c68a82846e573def9a7689d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 20 Sep 2013 11:48:37 +0200 Subject: [PATCH 2/3] [FIX] point_of_sale: barcode scanner was not working in firefox due to usage of event.keyCode instead of event.which bzr revid: fva@openerp.com-20130920094837-nks57e8qk3rgfksc --- addons/point_of_sale/static/src/js/devices.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index bc697e96aca..1d35a0cc08b 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -540,10 +540,9 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // The barcode readers acts as a keyboard, we catch all keyup events and try to find a // barcode sequence in the typed keys, then act accordingly. - $('body').delegate('','keypress', function (e){ - //console.log('keyup:'+String.fromCharCode(e.keyCode)+' '+e.keyCode,e); + this.handler = function(e){ //We only care about numbers - if (e.keyCode >= 48 && e.keyCode < 58){ + if (e.which >= 48 && e.which < 58){ // The barcode reader sends keystrokes with a specific interval. // We look if the typed keys fit in the interval. @@ -556,7 +555,7 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal timeStamp = new Date().getTime(); } } - codeNumbers.push(e.keyCode - 48); + codeNumbers.push(e.which - 48); lastTimeStamp = new Date().getTime(); if (codeNumbers.length === 13) { //We have found what seems to be a valid codebar @@ -567,12 +566,13 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal // NaN codeNumbers = []; } - }); + }; + $('body').on('keypress', this.handler); }, // stops catching keyboard events disconnect: function(){ - $('body').undelegate('', 'keyup') + $('body').off('keypress', this.handler) }, }); From 5a4b68e4222350213a5ec384681b44ca27e5db4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Fri, 20 Sep 2013 14:30:18 +0200 Subject: [PATCH 3/3] [FIX] point_of_sale: currency should be fetched from the pricelist instead of the company bzr revid: fva@openerp.com-20130920123018-b10rrmxmx85ludth --- addons/point_of_sale/static/src/js/models.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 6d5fd1fc422..f0200bf434c 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -52,6 +52,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal 'pos_config': null, 'units': null, 'units_by_id': null, + 'pricelist': null, 'selectedOrder': null, }); @@ -113,10 +114,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }).then(function(company_partners){ self.get('company').contact_address = company_partners[0].contact_address; - return self.fetch('res.currency',['symbol','position','rounding','accuracy'],[['id','=',self.get('company').currency_id[0]]]); - }).then(function(currencies){ - self.set('currency',currencies[0]); - return self.fetch('product.uom', null, null); }).then(function(units){ self.set('units',units); @@ -172,6 +169,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }).then(function(shops){ self.set('shop',shops[0]); + return self.fetch('product.pricelist',['currency_id'],[['id','=',self.get('pos_config').pricelist_id[0]]]); + }).then(function(pricelists){ + self.set('pricelist',pricelists[0]); + + return self.fetch('res.currency',['symbol','position','rounding','accuracy'],[['id','=',self.get('pricelist').currency_id[0]]]); + }).then(function(currencies){ + self.set('currency',currencies[0]); + return self.fetch('product.packaging',['ean','product_id']); }).then(function(packagings){ self.db.add_packagings(packagings); @@ -185,7 +190,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal ['name', 'list_price','price','pos_categ_id', 'taxes_id', 'ean13', 'default_code', 'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description'], [['sale_ok','=',true],['available_in_pos','=',true]], - {pricelist: self.get('pos_config').pricelist_id[0]} // context for price + {pricelist: self.get('pricelist').id} // context for price ); }).then(function(products){ self.db.add_products(products);