[IMP] point_of_sale: add a method for getting totals by product categories, used for custom receipts
This commit is contained in:
committed by
Frédéric van der Essen
parent
32fcfa657c
commit
d18e7f008c
@@ -122,6 +122,17 @@ function openerp_pos_db(instance, module){
|
||||
}
|
||||
make_ancestors(this.root_category_id, []);
|
||||
},
|
||||
category_contains: function(categ_id, product_id) {
|
||||
var product = this.product_by_id[product_id];
|
||||
if (product) {
|
||||
var cid = product.pos_categ_id[0];
|
||||
while (cid && cid !== categ_id){
|
||||
cid = this.category_parent[cid];
|
||||
}
|
||||
return !!cid;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/* loads a record store from the database. returns default if nothing is found */
|
||||
load: function(store,deft){
|
||||
if(this.cache[store] !== undefined){
|
||||
|
||||
@@ -1479,6 +1479,26 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
|
||||
|
||||
return fulldetails;
|
||||
},
|
||||
// Returns a total only for the orderlines with products belonging to the category
|
||||
get_total_for_category_with_tax: function(categ_id){
|
||||
var total = 0;
|
||||
var self = this;
|
||||
|
||||
if (categ_id instanceof Array) {
|
||||
for (var i = 0; i < categ_id.length; i++) {
|
||||
total += this.get_total_for_category_with_tax(categ_id[i]);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
this.orderlines.each(function(line){
|
||||
if ( self.pos.db.category_contains(categ_id,line.product.id) ) {
|
||||
total += line.get_price_with_tax();
|
||||
}
|
||||
});
|
||||
|
||||
return total;
|
||||
},
|
||||
get_change: function(paymentline) {
|
||||
if (!paymentline) {
|
||||
var change = this.get_total_paid() - this.get_total_with_tax();
|
||||
|
||||
Reference in New Issue
Block a user