From 06754b3237a44d8ba2a18bf407a3e65447ca390c Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 6 Sep 2016 17:50:06 +0200 Subject: [PATCH] [FIX] point_of_sale: tax calculation Inconsistencies can arise between the tax calculation performed in the PoS and in the backend (e.g. in a SO). For example: - Unit price: 9.479 - Tax: excluded, 5.5 % - Buy 5 units - Round globally In the backend, the result is 47.40 + 2.60 = 50.00 In the PoS, the result is 47.40 + 2.61 = 50.01 We make the PoS apply the same logic than in the backend. First, at the level of the `compute_all` method, especially to use the appropriate rounding precision before starting the calculation (so we move the rounding of `total_excluded` after the rounding precision adjustment). Then, by calculating the taxes amount as the difference between `priceWithTax` with `priceWithoutTax`. This is mandatory since they contain the result of `compute_all` in which the rounding logic has already been applied. opw-680891 --- addons/point_of_sale/static/src/js/models.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 6bff153e8a1..ec0eede134a 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1337,13 +1337,14 @@ exports.Orderline = Backbone.Model.extend({ }, compute_all: function(taxes, price_unit, quantity, currency_rounding) { var self = this; - var total_excluded = round_pr(price_unit * quantity, currency_rounding); - var total_included = total_excluded; - var base = total_excluded; var list_taxes = []; + var currency_rounding_bak = currency_rounding; if (this.pos.company.tax_calculation_rounding_method == "round_globally"){ currency_rounding = currency_rounding * 0.00001; } + var total_excluded = round_pr(price_unit * quantity, currency_rounding); + var total_included = total_excluded; + var base = total_excluded; _(taxes).each(function(tax) { tax = self._map_tax_fiscal_position(tax); if (tax.amount_type === 'group'){ @@ -1377,11 +1378,14 @@ exports.Orderline = Backbone.Model.extend({ } } }); - return {taxes: list_taxes, total_excluded: total_excluded, total_included: total_included}; + return { + taxes: list_taxes, + total_excluded: round_pr(total_excluded, currency_rounding_bak), + total_included: round_pr(total_included, currency_rounding_bak) + }; }, get_all_prices: function(){ var price_unit = this.get_unit_price() * (1.0 - (this.get_discount() / 100.0)); - var taxtotal = 0; var product = this.get_product(); var taxes_ids = product.taxes_id; @@ -1397,14 +1401,13 @@ exports.Orderline = Backbone.Model.extend({ var all_taxes = this.compute_all(product_taxes, price_unit, this.get_quantity(), this.pos.currency.rounding); _(all_taxes.taxes).each(function(tax) { - taxtotal += tax.amount; taxdetail[tax.id] = tax.amount; }); return { "priceWithTax": all_taxes.total_included, "priceWithoutTax": all_taxes.total_excluded, - "tax": taxtotal, + "tax": all_taxes.total_included - all_taxes.total_excluded, "taxDetails": taxdetail, }; },