From d82f9f6c9deaed9fcdb47247ce82e2a54b2510b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20van=20der=20Essen?= Date: Thu, 24 May 2012 17:33:15 +0200 Subject: [PATCH] [FIX] point_of_sale: only show weightable products in scale screens bzr revid: fva@openerp.com-20120524153315-wa67qcyldrui8nrf --- .../point_of_sale/static/src/js/pos_models.js | 22 ++++++++++++++-- .../static/src/js/pos_screens.js | 1 + .../static/src/js/pos_widgets.js | 25 +++++++++++-------- 3 files changed, 36 insertions(+), 12 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 9527c69f651..6b892c10863 100644 --- a/addons/point_of_sale/static/src/js/pos_models.js +++ b/addons/point_of_sale/static/src/js/pos_models.js @@ -94,7 +94,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal // We fetch the backend data on the server asynchronously - var cat_def = fetch('pos.category', ['name', 'parent_id', 'child_id']) + var cat_def = fetch('pos.category', ['id','name', 'parent_id', 'child_id', 'to_weight']) .pipe(function(result){ return self.set({'categories': result}); }); @@ -107,6 +107,24 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal self.set({'product_list': result}); }); + // associate the products with their categories + var prod_process_def = $.when(cat_def, prod_def) + .pipe(function(){ + var product_list = self.get('product_list'); + var categories = self.get('categories'); + var cat_by_id = {}; + for(var i = 0; i < categories.length; i++){ + cat_by_id[categories[i].id] = categories[i]; + } + //set the parent in the category + for(var i = 0; i < categories.length; i++){ + categories[i].parent_category = cat_by_id[categories[i].parent_id[0]]; + } + for(var i = 0; i < product_list.length; i++){ + product_list[i].pos_category = cat_by_id[product_list[i].pos_categ_id[0]]; + } + }); + var tax_def = fetch('account.tax', ['amount','price_include','type']) .then(function(result){ @@ -180,7 +198,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal }); // when all the data has loaded, we compute some stuff, and declare the Pos ready to be used. - $.when(cat_def, prod_def, session_def, tax_def, this.get_app_data(), this.flush()) + $.when(cat_def, prod_def, session_def, tax_def, prod_process_def, this.get_app_data(), this.flush()) .then(function(){ self.build_tree(); self.set({'cashRegisters' : new module.CashRegisterCollection(self.get('bank_statements'))}); 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 4281125dd27..9a4afe58289 100644 --- a/addons/point_of_sale/static/src/js/pos_screens.js +++ b/addons/point_of_sale/static/src/js/pos_screens.js @@ -309,6 +309,7 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa this.product_list_widget = new module.ProductListWidget(null,{ pos:this.pos, pos_widget:this.pos_widget, + only_weightable: true, weight: this.pos.proxy.weighting_read_kg(), }); this.product_list_widget.replace($('.placeholder-ProductListWidget')); 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 cd910fea45c..84690aaa7bb 100644 --- a/addons/point_of_sale/static/src/js/pos_widgets.js +++ b/addons/point_of_sale/static/src/js/pos_widgets.js @@ -496,6 +496,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa this.pos.get('products').bind('reset', this.renderElement, this); this.product_list = []; this.weight = options.weight; + this.only_weightable = options.only_weightable || false; this.next_screen = options.next_screen || false; }, set_weight: function(weight){ @@ -512,17 +513,21 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa var self = this; this._super(); this.product_list = []; - this.pos.get('products').chain().map(function(product) { - var product = new module.ProductWidget(this, { - model: product, - pos: self.pos, - weight: self.weight, - pos_widget: self.pos_widget, //FIXME ARGH + this.pos.get('products') + .chain() + .filter(function(product){ + // if only weightable, only keeps those with a to_weight category, keep all otherwise + return !self.only_weightable || (product.get('pos_category') && product.get('pos_category').to_weight); }) - self.product_list.push(product); - return product; - }).invoke('appendTo', this.$element); - return this; + .map(function(product) { + var product = new module.ProductWidget(this, { + model: product, + weight: self.weight, + }) + self.product_list.push(product); + return product; + }) + .invoke('appendTo', this.$element); }, });