From 57a30cc8c32ac62922fb25220c42ed7968eeef91 Mon Sep 17 00:00:00 2001 From: PabloCM Date: Tue, 21 Jul 2015 12:12:32 +0200 Subject: [PATCH] [FIX] Fiscal position tax mapping It was adding to the product all the right-handed taxes found in the fiscal position, not taking into account the product source tax. --- pos_pricelist/static/src/js/db.js | 15 ++++++++--- pos_pricelist/static/src/js/models.js | 36 ++++++++------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/pos_pricelist/static/src/js/db.js b/pos_pricelist/static/src/js/db.js index d67950df..4a8e6e62 100644 --- a/pos_pricelist/static/src/js/db.js +++ b/pos_pricelist/static/src/js/db.js @@ -140,15 +140,24 @@ function pos_pricelist_db(instance, module) { }); return list; }, - find_taxes_by_fiscal_position_id: function (fiscal_position_id) { + find_taxes_by_fiscal_position_id: function (fiscal_position_id, taxes_ids) { var taxes = []; + var found_taxes = {}; for (var id in this.fiscal_position_tax_by_id) { var tax = this.fiscal_position_tax_by_id[id]; if (tax && tax.position_id && - tax.position_id[0] == fiscal_position_id) { - taxes.push(tax); + tax.position_id[0] == fiscal_position_id && + taxes_ids.indexOf(tax.tax_src_id[0]) > -1) { + taxes.push(tax.tax_dest_id[0]); + found_taxes[tax.tax_src_id[0]] = true; } } + for (var i = 0, len = taxes_ids.length; i < len; i++) { + var tax_id = taxes_ids[i]; + if (! tax_id in found_taxes) { + taxes.push(tax_id); + } + } return taxes; }, add_products: function (products) { diff --git a/pos_pricelist/static/src/js/models.js b/pos_pricelist/static/src/js/models.js index f6ff413b..35f59be5 100644 --- a/pos_pricelist/static/src/js/models.js +++ b/pos_pricelist/static/src/js/models.js @@ -264,38 +264,24 @@ function pos_pricelist_models(instance, module) { get_applicable_taxes_for_orderline: function () { // find applicable taxes for this product and this customer var fiscal_position_taxes = []; - var product_taxes = []; var product = this.get_product(); - var partner = this.order ? this.order.get_client() : null; + var product_tax_ids = product.taxes_id; + var product_taxes = []; var taxes = this.pos.taxes; + var partner = this.order ? this.order.get_client() : null; if (partner && partner.property_account_position) { - fiscal_position_taxes = + product_tax_ids = this.pos.db.find_taxes_by_fiscal_position_id( - partner.property_account_position[0] + partner.property_account_position[0], product_tax_ids ); } - for (var i = 0, ilen = fiscal_position_taxes.length; + for (var i = 0, ilen = product_tax_ids.length; i < ilen; i++) { - var fp_tax = fiscal_position_taxes[i]; - for (var j = 0, jlen = taxes.length; j < jlen; j++) { - var p_tax = taxes[j]; - if (fp_tax && p_tax && fp_tax.tax_src_id[0] === p_tax.id) { - var dest_tax = _.detect(taxes, function (t) { - return t.id === fp_tax.tax_dest_id[0]; - }); - product_taxes.push(dest_tax); - } - } - } - if (product_taxes.length === 0) { - for (var i = 0, ilen = product.taxes_id.length; - i < ilen; i++) { - var _id = product.taxes_id[i]; - var p_tax = _.detect(taxes, function (t) { - return t.id === _id; - }); - product_taxes.push(p_tax); - } + var tax_id = product_tax_ids[i]; + var tax = _.detect(taxes, function (t) { + return t.id === tax_id; + }); + product_taxes.push(tax); } return product_taxes; },