From 701fd43f6dc7c01eb709d650fced85a4346af7c9 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 26 Jul 2019 09:21:45 +0000 Subject: [PATCH] [FIX] point_of_sale: order total round globally Before this commit, the amount total of an order in round_globally was simply the sum of all taxes amounts, then rounded This is plain wrong, as the accepted semantics of round globally is that: - each tax for each line is computed without rounding - then each taxes is summed across all order lines - then that amount is rounded - then all those rounded tax amount are summed together After this commit, this semantics is implemented closes odoo/odoo#35211 Signed-off-by: Lucas Perais (lpe) --- addons/point_of_sale/static/src/js/models.js | 33 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 8afbf4a0920..7575bf42048 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2488,9 +2488,36 @@ exports.Order = Backbone.Model.extend({ }), 0), this.pos.currency.rounding); }, get_total_tax: function() { - return round_pr(this.orderlines.reduce((function(sum, orderLine) { - return sum + orderLine.get_tax(); - }), 0), this.pos.currency.rounding); + if (this.pos.company.tax_calculation_rounding_method === "round_globally") { + // As always, we need: + // 1. For each tax, sum their amount across all order lines + // 2. Round that result + // 3. Sum all those rounded amounts + var groupTaxes = {}; + this.orderlines.each(function (line) { + var taxDetails = line.get_tax_details(); + var taxIds = Object.keys(taxDetails); + for (var t = 0; t