From 74c21caeb93a1c19f4d17a4d8d7aa887d8616f49 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Mon, 11 Jul 2022 08:38:40 +0000 Subject: [PATCH] [FIX] point_of_sale: display product price with fiscal pos When the price of the products is displayed in the product screen, we are now taking into account the taxes when the pos diplays taxes included. The issue is that we are using the taxes on the product, and we are not applying the fiscal position of the current order on the price. We are now taking it into account OPW-2860737 closes odoo/odoo#95848 X-original-commit: e162a7084f584fc9b5d5b2db7f519b5b47ad6406 Signed-off-by: Masereel Pierre --- addons/point_of_sale/static/src/js/models.js | 88 +++++++++++--------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 32ccbd13aac..bdc513b8cf0 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1065,9 +1065,53 @@ class PosGlobalState extends PosModel { 'taxes': taxes_vals, 'total_excluded': sign * round_pr(total_excluded, this.currency.rounding), 'total_included': sign * round_pr(total_included, this.currency.rounding), - } + }; } + _map_tax_fiscal_position(tax, order = false) { + var self = this; + var current_order = order || this.get_order(); + var order_fiscal_position = current_order && current_order.fiscal_position; + var taxes = []; + + if (order_fiscal_position) { + var tax_mappings = _.filter(order_fiscal_position.fiscal_position_taxes_by_id, function (fiscal_position_tax) { + return fiscal_position_tax.tax_src_id[0] === tax.id; + }); + + if (tax_mappings && tax_mappings.length) { + _.each(tax_mappings, function(tm) { + if (tm.tax_dest_id) { + var taxe = self.taxes_by_id[tm.tax_dest_id[0]]; + if (taxe) { + taxes.push(taxe); + } + } + }); + } else{ + taxes.push(tax); + } + } else { + taxes.push(tax); + } + + return taxes; + } + + get_taxes_after_fp(taxes_ids){ + var self = this; + var taxes = this.taxes; + var product_taxes = []; + _(taxes_ids).each(function(el){ + var tax = _.detect(taxes, function(t){ + return t.id === el; + }); + product_taxes.push.apply(product_taxes, self._map_tax_fiscal_position(tax)); + }); + product_taxes = _.uniq(product_taxes, function(tax) { return tax.id; }); + return product_taxes; + } + /** * TODO: We can probably remove this here and put it somewhere else. * And that somewhere else becomes the parent of the proxy. @@ -1314,7 +1358,7 @@ class Product extends PosModel { } get_display_price(pricelist, quantity) { if (this.pos.config.iface_tax_included === 'total') { - const taxes = this.taxes_id.map(id => this.pos.taxes_by_id[id]); + const taxes = this.pos.get_taxes_after_fp(this.taxes_id); const allPrices = this.pos.compute_all(taxes, this.get_price(pricelist, quantity), 1, this.pos.currency.rounding); return allPrices.total_included; } else { @@ -1766,17 +1810,7 @@ class Orderline extends PosModel { return round_pr(this.get_unit_price() * this.get_quantity() * (1 - this.get_discount()/100), rounding); } get_taxes_after_fp(taxes_ids){ - var self = this; - var taxes = this.pos.taxes; - var product_taxes = []; - _(taxes_ids).each(function(el){ - var tax = _.detect(taxes, function(t){ - return t.id === el; - }); - product_taxes.push.apply(product_taxes, self._map_tax_fiscal_position(tax, self.order)); - }); - product_taxes = _.uniq(product_taxes, function(tax) { return tax.id; }); - return product_taxes; + return this.pos.get_taxes_after_fp(taxes_ids); } get_display_price_one(){ var rounding = this.pos.currency.rounding; @@ -1842,33 +1876,7 @@ class Orderline extends PosModel { return taxes; } _map_tax_fiscal_position(tax, order = false) { - var self = this; - var current_order = order || this.pos.get_order(); - var order_fiscal_position = current_order && current_order.fiscal_position; - var taxes = []; - - if (order_fiscal_position) { - var tax_mappings = _.filter(order_fiscal_position.fiscal_position_taxes_by_id, function (fiscal_position_tax) { - return fiscal_position_tax.tax_src_id[0] === tax.id; - }); - - if (tax_mappings && tax_mappings.length) { - _.each(tax_mappings, function(tm) { - if (tm.tax_dest_id) { - var taxe = self.pos.taxes_by_id[tm.tax_dest_id[0]]; - if (taxe) { - taxes.push(taxe); - } - } - }); - } else{ - taxes.push(tax); - } - } else { - taxes.push(tax); - } - - return taxes; + return this.pos._map_tax_fiscal_position(tax, order); } /** * Mirror JS method of: