[FIX] point_of_sale: only show weightable products in scale screens

bzr revid: fva@openerp.com-20120524153315-wa67qcyldrui8nrf
This commit is contained in:
Frédéric van der Essen 2012-05-24 17:33:15 +02:00
parent f5679b7b8d
commit d82f9f6c9d
3 changed files with 36 additions and 12 deletions

View File

@ -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'))});

View File

@ -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'));

View File

@ -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);
},
});