From f25e72609623d36f5c3c564daf69e1bdb4dabc04 Mon Sep 17 00:00:00 2001 From: Frederic van der Essen Date: Mon, 10 Nov 2014 19:28:59 +0100 Subject: [PATCH] [IMP] point_of_sale: add helper function to compute tax-specific subtotals, useful for receipt customization --- addons/point_of_sale/static/src/js/models.js | 43 +++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 034d13edb35..23817342084 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -194,7 +194,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal model: 'account.tax', fields: ['name','amount', 'price_include', 'type'], domain: null, - loaded: function(self,taxes){ self.taxes = taxes; }, + loaded: function(self,taxes){ + self.taxes = taxes; + self.taxes_by_id = {}; + + for (var i = 0; i < taxes.length; i++) { + self.taxes_by_id[taxes[i].id] = taxes[i]; + } + }, },{ model: 'pos.session', fields: ['id', 'journal_ids','name','user_id','config_id','start_at','stop_at','sequence_number','login_number'], @@ -948,6 +955,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal get_tax_details: function(){ return this.get_all_prices().taxDetails; }, + get_taxes: function(){ + var taxes_ids = this.get_product().taxes_id; + var taxes = []; + for (var i = 0; i < taxes_ids.length; i++) { + taxes.push(this.pos.taxes_by_id[taxes_ids[i]]); + } + return taxes; + }, get_all_prices: function(){ var self = this; var currency_rounding = this.pos.currency.rounding; @@ -1490,6 +1505,32 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal return total; }, + get_total_for_taxes: function(tax_id){ + var total = 0; + var self = this; + + if (!(tax_id instanceof Array)) { + tax_id = [tax_id]; + } + + var tax_set = {}; + + for (var i = 0; i < tax_id.length; i++) { + tax_set[tax_id[i]] = true; + } + + this.orderlines.each(function(line){ + var taxes_ids = line.get_product().taxes_id; + for (var i = 0; i < taxes_ids.length; i++) { + if (tax_set[taxes_ids[i]]) { + total += line.get_price_with_tax(); + return; + } + } + }); + + return total; + }, get_change: function(paymentline) { if (!paymentline) { var change = this.get_total_paid() - this.get_total_with_tax();