From d4cbce0ce75f997dda11fe3f51b49faff8c95103 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Tue, 8 May 2012 14:37:01 +0200 Subject: [PATCH] barcode scanning fixes bzr revid: fva@openerp.com-20120508123701-pb641zlrwd183pf1 --- addons/point_of_sale/static/src/css/pos.css | 3 + addons/point_of_sale/static/src/js/pos_devices.js | 63 +++++++--- addons/point_of_sale/static/src/js/pos_models.js | 1 - addons/point_of_sale/static/src/js/pos_screens.js | 130 +++++++++++---------- addons/point_of_sale/static/src/js/pos_widgets.js | 27 ++++- addons/point_of_sale/static/src/xml/pos.xml | 10 +- 6 files changed, 147 insertions(+), 87 deletions(-) diff --git a/addons/point_of_sale/static/src/css/pos.css b/addons/point_of_sale/static/src/css/pos.css index e566482..4ba5520 100644 --- a/addons/point_of_sale/static/src/css/pos.css +++ b/addons/point_of_sale/static/src/css/pos.css @@ -418,6 +418,9 @@ body{ margin-top: 0px; padding-top: 7px; } +.point-of-sale .step-screen p{ + font-size: 18px; +} .point-of-sale .pos-step-container { display: inline-block; diff --git a/addons/point_of_sale/static/src/js/pos_devices.js b/addons/point_of_sale/static/src/js/pos_devices.js index ea10169..e9c6941 100644 --- a/addons/point_of_sale/static/src/js/pos_devices.js +++ b/addons/point_of_sale/static/src/js/pos_devices.js @@ -1,6 +1,8 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sale + var QWeb = instance.web.qweb; + window.debug_devices = new (instance.web.Class.extend({ payment_status: 'waiting_for_payment', weight: 0, @@ -75,7 +77,7 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa }, // called when the client logs in or starts to scan product - transation_start: function(){ + transaction_start: function(){ console.log('PROXY: transaction start'); }, @@ -103,12 +105,17 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa init: function(attributes){ this.pos = attributes.pos; - this.action_callbacks = { + this.action_callback = { 'product': undefined, 'cashier': undefined, 'client': undefined, 'discount': undefined, }; + this.price_prefix_set = attributes.price_prefix_set || {'02':'', '22':'', '24':'', '26':'', '28':''}; + this.weight_prefix_set = attributes.weight_prefix_set || {'21':'','23':'','27':'','29':'','25':''}; + this.client_prefix_set = attributes.weight_prefix_set || {'42':''}; + this.cashier_prefix_set = attributes.weight_prefix_set || {'43':''}; + this.discount_prefix_set = attributes.weight_prefix_set || {'44':''}; }, // when an ean is scanned and parsed, the callback corresponding @@ -124,14 +131,14 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa set_action_callbacks: function(callbacks){ for(action in callbacks){ - this.action_callbacks[action] = callbacks[action]; + this.action_callback[action] = callbacks[action]; } }, //remove all action callbacks reset_action_callbacks: function(){ - for(action in this.action_callbacks){ - this.action_callbacks[action] = undefined; + for(action in this.action_callback){ + this.action_callback[action] = undefined; } }, @@ -140,6 +147,9 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa // ean must be a string check_ean: function(ean){ var code = ean.split(''); + for(var i = 0; i < code.length; i++){ + code[i] = Number(code[i]); + } var st1 = code.slice(); var st2 = st1.slice(0,st1.length-1).reverse(); // some EAN13 barcodes have a length of 12, as they start by 0 @@ -196,18 +206,32 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa if(!this.check_ean(ean)){ parse_result.type = 'error'; - }else if (prefix2 in {'02':'', '22':'', '24':'', '26':'', '28':''}){ + }else if (prefix2 in this.price_prefix_set){ parse_result.type = 'price'; parse_result.prefix = prefix2; parse_result.id = ean.substring(0,7); parse_result.value = Number(ean.substring(7,12))/100.0; parse_result.unit = 'euro'; - } else if (prefix2 in {'21':'','23':'','27':'','29':'','25':''}) { + } else if (prefix2 in this.price_prefix_set){ parse_result.type = 'weight'; parse_result.prefix = prefix2; - prase_result.id = ean.substring(0,7); + parse_result.id = ean.substring(0,7); parse_result.value = Number(ean.substring(7,12))/1000.0; parse_result.unit = 'Kg'; + }else if (prefix2 in this.client_prefix_set){ + parse_result.type = 'client'; + parse_result.prefix = prefix2; + parse_result.id = ean.substring(0,7); + }else if (prefix2 in this.cashier_prefix_set){ + parse_result.type = 'cashier'; + parse_result.prefix = prefix2; + parse_result.id = ean.substring(0,7); + }else if (prefix2 in this.discount_prefix_set){ + parse_result.type = 'discount'; + parse_result.prefix = prefix2; + parse_result.id = ean.substring(0,7); + parse_result.value = Number(ean.substring(7,12))/100.0; + parse_result.unit = '%'; }else{ parse_result.type = 'unit'; parse_result.prefix = ''; @@ -224,6 +248,8 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa var scannedProductModel = undefined; var parse_result = this.parse_ean(ean); + console.log('getting products:',ean,parse_result,allProducts); + if (parse_result.type === 'price') { var itemCode = parse_result.id; var scannedPackaging = _.detect(allPackages, function(pack) { return pack.ean !== undefined && pack.ean.substring(0,7) === itemCode;}); @@ -249,6 +275,7 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa // a default callback for the 'product' action. It will select the product // corresponding to the ean and add it to the current order. scan_product_callback: function(parse_result){ + var self = this; var selectedOrder = self.pos.get('selectedOrder'); var scannedProductModel = self.get_product_by_ean(parse_result.ean); if (scannedProductModel === undefined) { @@ -283,15 +310,18 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa }; if(parse_result.type in {'unit':'', 'weight':'', 'price':''}){ //ean is associated to a product + console.log('calling product callback'); if(this.action_callback['product']){ + console.log('found product callback'); this.action_callback['product'](parse_result); } }else{ + console.log('calling callback:',parse_result.type); if(this.action_callback[parse_result.type]){ + console.log('found product callback'); this.action_callback[parse_result.type](parse_result); } } - }, // starts catching keyboard events and tries to interpret codebar @@ -324,7 +354,8 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa lastTimeStamp = new Date().getTime(); if (codeNumbers.length == 13) { //We have found what seems to be a valid codebar - var parse_result = this.parse_ean(codeNumbers.join('')); + var parse_result = self.parse_ean(codeNumbers.join('')); + console.log('BARCODE:',parse_result); if (parse_result.type === 'error') { //most likely a checksum error, raise warning $(QWeb.render('pos-scan-warning')).dialog({ @@ -334,13 +365,17 @@ function openerp_pos_devices(module, instance){ //module is instance.point_of_sa title: "Warning", }); }else if(parse_result.type in {'unit':'', 'weight':'', 'price':''}){ //ean is associated to a product - if(this.action_callback['product']){ - this.action_callback['product'](parse_result); + console.log('calling product callback'); + if(self.action_callback['product']){ + console.log('found product callback'); + self.action_callback['product'](parse_result); } //this.trigger("codebar",parse_result ); }else{ - if(this.action_callback[parse_result.type]){ - this.action_callback[parse_result.type](parse_result); + console.log('calling callback:',parse_result.type); + if(self.action_callback[parse_result.type]){ + console.log('found callback'); + self.action_callback[parse_result.type](parse_result); } } diff --git a/addons/point_of_sale/static/src/js/pos_models.js b/addons/point_of_sale/static/src/js/pos_models.js index 1ea09b5..8a43677 100644 --- a/addons/point_of_sale/static/src/js/pos_models.js +++ b/addons/point_of_sale/static/src/js/pos_models.js @@ -431,7 +431,6 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal existing = (this.get('orderLines')).get(product.id); if (existing != null) { if(existing.get('weighted')){ - console.log('TODO VERIFY THIS'); existing.incrementWeight(product.attributes.weight); }else{ existing.incrementQuantity(); diff --git a/addons/point_of_sale/static/src/js/pos_screens.js b/addons/point_of_sale/static/src/js/pos_screens.js index 1f478a8..a9c49bf 100644 --- a/addons/point_of_sale/static/src/js/pos_screens.js +++ b/addons/point_of_sale/static/src/js/pos_screens.js @@ -60,8 +60,7 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa this.current_popup = null; - this.default_mode = options.default_mode || 'client'; - this.current_mode = this.default_mode; + this.current_mode = options.default_mode || 'client'; this.current_screen = this.current_mode === 'client' ? this.current_client_screen: @@ -113,45 +112,28 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa } }, load_saved_screen: function(){ - console.log('load_saved_screen'); this.close_popup(); - if(true || this.selected_order != this.pos.get('selectedOrder')){ - var selectedOrder = this.pos.get('selectedOrder'); - - var user_mode = this.current_mode; //selectedOrder.get('user_mode'); - console.log('user mode:',user_mode); - - if(user_mode === 'client'){ - this.current_mode = 'client'; - this.set_current_screen(selectedOrder.get('client_screen') || this.default_client_screen); - }else if(user_mode === 'cashier'){ - this.current_mode = 'cashier'; - console.log('default_cashier_screen:',this.default_cashier_screen); - this.set_current_screen(selectedOrder.get('cashier_screen') || this.default_cashier_screen); - }else{ - this.current_mode = this.default_mode; - selectedOrder.set({ user_mode: this.current_mode }); - if(this.current_mode === 'client'){ - this.set_current_screen(this.default_client_screen); - }else{ - this.set_current_screen(this.default_cashier_screen); - } - } - this.selected_order = selectedOrder; - // var screen = this.pos.get('selectedOrder').get('screen') || this.default_screen; - // this.selected_order = this.pos.get('selectedOrder'); - // this.set_current_screen(screen); + + var selectedOrder = this.pos.get('selectedOrder'); + + if(this.current_mode === 'client'){ + this.set_current_screen(selectedOrder.get('client_screen') || this.default_client_screen); + }else if(this.current_mode === 'cashier'){ + console.log('default_cashier_screen:',this.default_cashier_screen); + this.set_current_screen(selectedOrder.get('cashier_screen') || this.default_cashier_screen); } + this.selected_order = selectedOrder; }, set_user_mode: function(user_mode){ - console.log('set user mode:',user_mode); if(user_mode !== this.current_mode){ this.close_popup(); this.current_mode = user_mode; - this.pos.get('selectedOrder').set({ user_mode : this.current_mode }); this.load_saved_screen(); } }, + get_user_mode: function(){ + return this.current_mode; + }, set_current_screen: function(screen_name){ var screen = this.screen_set[screen_name]; @@ -163,7 +145,6 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa selectedOrder.set({'cashier_screen': screen_name}); } - // console.log('Set Current Screen: '+screen_name+' :',screen,'old:',this.current_screen, 'mode:',this.current_mode); if(screen && screen !== this.current_screen){ if(this.current_screen){ this.current_screen.hide(); @@ -282,7 +263,7 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa { label: 'back', icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png', - click: function(){ //TODO Go to ask for weighting screen + click: function(){ clearInterval(this.intervalID); self.pos.proxy.weighting_end(); self.pos.screen_selector.set_current_screen('scan'); @@ -313,37 +294,56 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa show: function(){ this._super(); var self = this; - - this.pos_widget.set_numpad_visible(false); - this.pos_widget.set_leftpane_visible(true); - this.pos_widget.set_cashier_controls_visible(false); - this.pos_widget.action_bar.set_total_visible(true); - this.pos_widget.action_bar.set_help_visible(true,function(){self.pos.screen_selector.show_popup('help');}); - this.pos_widget.action_bar.set_logout_visible(false); - - this.pos_widget.orderView.setNumpadState(this.pos_widget.numpadView.state); - this.pos_widget.action_bar.add_new_button( - { - label: 'back', - icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png', - click: function(){ - self.pos.screen_selector.set_current_screen('scan'); + if(this.pos.screen_selector.get_user_mode() === 'client'){ + this.pos_widget.set_numpad_visible(false); + this.pos_widget.set_leftpane_visible(true); + this.pos_widget.set_cashier_controls_visible(false); + this.pos_widget.action_bar.set_total_visible(true); + this.pos_widget.action_bar.set_help_visible(true,function(){self.pos.screen_selector.show_popup('help');}); + this.pos_widget.action_bar.set_logout_visible(false); + + this.pos_widget.orderView.setNumpadState(this.pos_widget.numpadView.state); + this.pos_widget.action_bar.add_new_button( + { + label: 'back', + icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png', + click: function(){ + self.pos.screen_selector.set_current_screen('scan'); + } } - } - ); - this.pos.barcode_reader.set_action_callbacks({ - 'cashier': function(ean){ - //TODO 'switch to cashier mode' - self.proxy.cashier_mode_activated(); - }, - }); + ); + this.pos.barcode_reader.set_action_callbacks({ + 'cashier': function(ean){ + self.proxy.cashier_mode_activated(); + }, + }); + this.product_list_widget.set_next_screen('scan'); + }else{ // user_mode === 'cashier' + this.pos_widget.set_numpad_visible(true); + this.pos_widget.set_leftpane_visible(true); + this.pos_widget.set_cashier_controls_visible(true); + this.pos_widget.action_bar.set_total_visible(true); + this.pos_widget.action_bar.set_help_visible(false); + + this.pos_widget.orderView.setNumpadState(this.pos_widget.numpadView.state); + this.pos_widget.action_bar.add_new_button( + { + label: 'back', + icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png', + click: function(){ + self.pos.screen_selector.set_current_screen('products'); + } + } + ); + this.product_list_widget.set_next_screen('undefined'); + } this.pos.proxy.weighting_start(); this.last_weight = this.product_list_widget.weight; this.intervalID = setInterval(function(){ var weight = self.pos.proxy.weighting_read_kg(); if(weight != self.last_weight){ - self.product_list_widget.setWeight(weight); + self.product_list_widget.set_weight(weight); self.last_weight = weight; } },500); @@ -355,7 +355,6 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa clearInterval(this.intervalID); this.pos.proxy.weighting_end(); }, - }); module.ClientPaymentScreenWidget = module.ScreenWidget.extend({ @@ -407,6 +406,10 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa }, }); }, + hide: function(){ + this._super(); + clearInterval(this.intervalID); + }, }); module.WelcomeScreenWidget = module.ScreenWidget.extend({ @@ -438,17 +441,18 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa ); this.pos.barcode_reader.set_action_callbacks({ 'product': function(ean){ - self.proxy.transaction_start(); + console.log('product!'); + self.pos.proxy.transaction_start(); self.pos.barcode_reader.scan_product_callback(ean); self.pos.screen_selector.set_current_screen('products'); }, 'cashier': function(ean){ //TODO 'switch to cashier mode' - self.proxy.cashier_mode_activated(); + self.pos.proxy.cashier_mode_activated(); self.pos.screen_selector.set_current_screen('products'); }, 'client': function(ean){ - self.proxy.transaction_start(); + self.pos.proxy.transaction_start(); //TODO 'log the client' self.pos.screen_selector.show_popup('receipt'); }, @@ -543,7 +547,8 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa { label: 'weight', icon: '/point_of_sale/static/src/img/icons/png48/scale.png', - click: function(){ //TODO Go to ask for weighting screen + click: function(){ + self.pos.screen_selector.set_current_screen('scale_product'); } } ); @@ -557,7 +562,6 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa } }, 'cashier': function(ean){ - //TODO 'switch to cashier mode' self.proxy.cashier_mode_activated(); }, 'discount': function(ean){ diff --git a/addons/point_of_sale/static/src/js/pos_widgets.js b/addons/point_of_sale/static/src/js/pos_widgets.js index 7fae267..834ec0c 100644 --- a/addons/point_of_sale/static/src/js/pos_widgets.js +++ b/addons/point_of_sale/static/src/js/pos_widgets.js @@ -244,21 +244,30 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa this.model = options.model; this.pos = options.pos; this.model.attributes.weight = options.weight || undefined; + this.next_screen = options.next_screen || undefined; }, addToOrder: function(event) { /* Preserve the category URL */ event.preventDefault(); return (this.pos.get('selectedOrder')).addProduct(this.model); }, - setWeight: function(weight){ + set_weight: function(weight){ this.model.attributes.weight = weight; this.renderElement(); }, + set_next_screen: function(screen){ + this.next_screen = screen; + }, renderElement: function() { + var self = this; this.$element.addClass("product"); this.$element.html(this.template_fct(this.model.toJSON())); - $("a", this.$element).click(_.bind(this.addToOrder, this)); - return this; + $("a", this.$element).click(function(e){ + self.addToOrder(e); + if(self.next_screen){ + self.pos.screen_selector.set_current_screen(self.next_screen); //FIXME There ought to be a better way to do this ... + } + }); }, }); @@ -527,10 +536,16 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa this.pos.get('products').bind('reset', this.renderElement, this); this.product_list = []; this.weight = options.weight; + this.next_screen = options.next_screen || false; + }, + set_weight: function(weight){ + for(var i = 0; i < this.product_list.length; i++){ + this.product_list[i].set_weight(weight); + } }, - setWeight: function(weight){ + set_next_screen: function(screen){ for(var i = 0; i < this.product_list.length; i++){ - this.product_list[i].setWeight(weight); + this.product_list[i].set_next_screen(screen); } }, renderElement: function() { @@ -974,9 +989,11 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa if(visible){ $('#numpad').show(); $('#paypad').show(); + $('#current-order').css({'bottom':'271px'}); }else{ $('#numpad').hide(); $('#paypad').hide(); + $('#current-order').css({'bottom':'0px'}); } } }, diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index eca8f0e..34d6bda 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -222,21 +222,23 @@

Welcome

-

please scan an item or your member card

+ +

Please scan an item or your member card

-

Scan your item

-

Please scan an item

+

Please scan an item

+

Payment

+

Please insert your card in the reader and follow the instructions to complete your purchase

@@ -245,7 +247,7 @@

Please put your product on the scale

-

+
-- 1.7.10.4