From d18e7f008c9daab717f4c8ff660bd3f0d787bcd0 Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Fri, 7 Nov 2014 17:25:42 +0100 Subject: [PATCH] [IMP] point_of_sale: add a method for getting totals by product categories, used for custom receipts --- addons/point_of_sale/static/src/js/db.js | 11 +++++++++++ addons/point_of_sale/static/src/js/models.js | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index 172a7c9dcf4..2711dbcf9f9 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -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){ diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 25570664a93..8c14ae6b667 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -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();