From 54ecdba716a348b18d71a77811a0f2ff8fc4be65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Mon, 4 Jun 2012 17:04:59 +0200 Subject: [PATCH] [FIX] point_of_sale: scale button removed when no scale, range check on discount & prices, skip receipt if printer bzr revid: fva@openerp.com-20120604150459-96z5e1h0kv02d4uo --- .../point_of_sale/static/src/js/pos_models.js | 31 ++++++-- .../static/src/js/pos_screens.js | 77 +++++++++++-------- .../static/src/js/pos_widgets.js | 11 ++- 3 files changed, 80 insertions(+), 39 deletions(-) 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 6174bb3f5e2..fbf806e7c38 100644 --- a/addons/point_of_sale/static/src/js/pos_models.js +++ b/addons/point_of_sale/static/src/js/pos_models.js @@ -173,12 +173,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal [['id','=', pos_session.config_id[0]]] ).then(function(result){ self.set({'pos_config': result[0]}); - this.use_scale = result[0].iface_electronic_scale || false; - this.use_proxy_printer = result[0].iface_print_via_proxy || false; - this.use_virtual_keyboard = result[0].iface_vkeyboard || false; - this.use_websql = result[0].iface_websql || false; - this.use_barcode_scanner = result[0].iface_barscan || false; - this.use_selfcheckout = result[0].iface_self_checkout || false; + console.log('POSXOFNFIG:',result[0]); + self.use_scale = result[0].iface_electronic_scale || false; + self.use_proxy_printer = result[0].iface_print_via_proxy || false; + self.use_virtual_keyboard = result[0].iface_vkeyboard || false; + self.use_websql = result[0].iface_websql || false; + self.use_barcode_scanner = result[0].iface_barscan || false; + self.use_selfcheckout = result[0].iface_self_checkout || false; + console.log('URERRUFUEGHHHHH'); }); var bank_def = fetch( @@ -508,6 +510,23 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }, this); }, + // we override the attributes set to prevent some out of range values + set: function(attributes, options){ + if(attributes.discount > 100){ + attributes.discount = 100; + }else if(attributes.discount < 0){ + attributes.discount = 0; + } + if(attributes.quantity < 0){ + attributes.quantity = 0; + } + if(attributes.list_price < 0){ + attributes.list_price = 0; + } + Backbone.Model.prototype.set.call(this,attributes,options); + return this; + }, + // when we add an new orderline we want to merge it with the last line to see reduce the number of items // in the orderline. This returns true if it makes sense to merge the two can_be_merged_with: function(orderline){ 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 459b28c2670..5ea6f95cd18 100644 --- a/addons/point_of_sale/static/src/js/pos_screens.js +++ b/addons/point_of_sale/static/src/js/pos_screens.js @@ -463,15 +463,17 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa this.pos_widget.action_bar.set_help_visible(true,function(){self.pos_widget.screen_selector.show_popup('help');}); this.pos_widget.action_bar.set_logout_visible(false); - this.pos_widget.action_bar.add_new_button( - { - label: 'weight', - icon: '/point_of_sale/static/src/img/icons/png48/scale.png', - click: function(){ - self.pos_widget.screen_selector.set_current_screen('scale_invite'); - } - } - ); + if(this.pos.use_scale){ + console.log('welcome weight'); + this.pos_widget.action_bar.add_new_button({ + label: 'weight', + icon: '/point_of_sale/static/src/img/icons/png48/scale.png', + click: function(){ + self.pos_widget.screen_selector.set_current_screen('scale_invite'); + } + }); + } + this.pos.barcode_reader.set_action_callbacks({ 'product': function(ean){ self.pos.proxy.transaction_start(); @@ -520,21 +522,24 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa this.pos_widget.action_bar.set_help_visible(true,function(){self.pos_widget.screen_selector.show_popup('help');}); this.pos_widget.action_bar.set_logout_visible(false); - this.pos_widget.action_bar.add_new_button( - { - label: 'weight', - icon: '/point_of_sale/static/src/img/icons/png48/scale.png', - click: function(){ //TODO Go to ask for weighting screen - self.pos_widget.screen_selector.set_current_screen('scale_invite'); - } - },{ + if(self.pos.use_scale){ + this.pos_widget.action_bar.add_new_button({ + label: 'weight', + icon: '/point_of_sale/static/src/img/icons/png48/scale.png', + click: function(){ //TODO Go to ask for weighting screen + self.pos_widget.screen_selector.set_current_screen('scale_invite'); + } + }); + } + + this.pos_widget.action_bar.add_new_button({ label: 'pay', icon: '/point_of_sale/static/src/img/icons/png48/go-next.png', click: function(){ self.pos_widget.screen_selector.set_current_screen('client_payment'); //TODO what stuff ? } - } - ); + }); + this.pos.barcode_reader.set_action_callbacks({ 'product': function(ean){ if(self.pos_widget.scan_product(ean)){ @@ -576,22 +581,26 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa 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.action_bar.set_logout_visible(true, function(){ - self.pos_widget.screen_selector.set_user_mode('client'); - }); + + this.pos_widget.action_bar.set_logout_visible(true, function(){ + self.pos_widget.screen_selector.set_user_mode('client'); + }); + this.product_categories_widget.reset_category(); //this.pos_widget.onscreen_keyboard.connect(); this.pos_widget.order_widget.set_numpad_state(this.pos_widget.numpad.state); - this.pos_widget.action_bar.add_new_button( - { - label: 'weight', - icon: '/point_of_sale/static/src/img/icons/png48/scale.png', - click: function(){ - self.pos_widget.screen_selector.set_current_screen('scale_product'); - } - } - ); + + if(this.pos.use_scale){ + this.pos_widget.action_bar.add_new_button({ + label: 'weight', + icon: '/point_of_sale/static/src/img/icons/png48/scale.png', + click: function(){ + self.pos_widget.screen_selector.set_current_screen('scale_product'); + } + }); + } + this.pos.barcode_reader.set_action_callbacks({ 'product': function(ean){ if(self.pos_widget.scan_product(ean)){ @@ -741,7 +750,11 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa this.pos.push_order(currentOrder.exportAsJSON()) .then(function() { self.validate_button.$element.removeAttr('disabled'); - self.pos_widget.screen_selector.set_current_screen('receipt'); + if(self.pos.use_proxy_printer){ + self.pos.get('selectedOrder').destroy(); //finish order and go back to scan screen + }else{ + self.pos_widget.screen_selector.set_current_screen('receipt'); + } }); }, bindPaymentLineEvents: function() { 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 1b8ecb6cf24..d4adf561279 100644 --- a/addons/point_of_sale/static/src/js/pos_widgets.js +++ b/addons/point_of_sale/static/src/js/pos_widgets.js @@ -1073,8 +1073,9 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa } }, close: function() { - if (confirm) + if (confirm){ close(); + } } }); } else { @@ -1084,6 +1085,14 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa }, close: function() { this.pos.barcode_reader.disconnect(); + return new session.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_close_statement']], ['res_id']).pipe( + _.bind(function(res) { + return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) { + var action = result.result; + action.context = _.extend(action.context || {}, {'cancel_action': {type: 'ir.actions.client', tag: 'default_home'}}); + this.do_action(action); + }, this)); + }, this)); }, destroy: function() { instance.webclient.set_content_full_screen(false);