From 4aa7e101a90f2281e581389e7c24909dd35fb00f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 10 Mar 2020 14:08:53 +0000 Subject: [PATCH] [FIX] point_of_sale: rounding error - Set 'Product Unit of Measure' to 5 - Set the UoM rounding to 0.001 - Create an excluded tax of 6 % - Create a product costing 7.0 - Open the POS, add the product with a quantity of 0.535 The tax is 0.22 instead of 0.23. The root cause of the issue is the in JS: ``` round_pr(0.535, Math.pow(10,-5)) * 7 = 3.744999999999999 round_pr(0.535, 0.00001) * 7 = 3.745 ``` The numerical error impacts the tax computation later on. As a workaround, we round by the maximum between the UoM rounding and the 'Product Unit of Measure', which is what will be done in the backend anyway. opw-2205092 closes odoo/odoo#47372 X-original-commit: 125cdf96e94a94146804091ad47e701240c2529e Signed-off-by: Nicolas Martinelli (nim) --- addons/point_of_sale/static/src/js/models.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index b3c832cc794..12c488793d0 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1517,9 +1517,9 @@ exports.Orderline = Backbone.Model.extend({ var unit = this.get_unit(); if(unit){ if (unit.rounding) { - this.quantity = round_pr(quant, unit.rounding); var decimals = this.pos.dp['Product Unit of Measure']; - this.quantity = round_di(this.quantity, decimals) + var rounding = Math.max(unit.rounding, Math.pow(10, -decimals)); + this.quantity = round_pr(quant, rounding); this.quantityStr = field_utils.format.float(this.quantity, {digits: [69, decimals]}); } else { this.quantity = round_pr(quant, 1);