From ae8bf42ca6e982aa2c1ffe06f90969d5faa8756b Mon Sep 17 00:00:00 2001 From: gawa-odoo Date: Fri, 27 Jan 2023 09:02:13 +0000 Subject: [PATCH] [FIX] account: round using line company instead of env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To compute the analytic amounts, we used the user company currency to know the precision to use to round, for the comparison. We should instead use the line's currency for the amounts, and the decimal precision for the distribution. closes odoo/odoo#114997 X-original-commit: a94517702c47aa9259c0cbea9b4763ab7501176f Signed-off-by: William André (wan) Signed-off-by: Wala Gauthier (gawa) --- addons/account/models/account_move_line.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 644bf7d8989..a0da574600e 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -7,7 +7,7 @@ from functools import lru_cache from odoo import api, fields, models, Command, _ from odoo.exceptions import ValidationError, UserError from odoo.osv import expression -from odoo.tools import frozendict, formatLang, format_date, float_is_zero, Query +from odoo.tools import frozendict, formatLang, format_date, float_compare from odoo.tools.sql import create_index from odoo.addons.web.controllers.utils import clean_action @@ -2723,7 +2723,7 @@ class AccountMoveLine(models.Model): for account_id, distribution in self.analytic_distribution.items(): line_values = self._prepare_analytic_distribution_line(float(distribution), account_id, distribution_on_each_plan) - if not float_is_zero(line_values.get("amount"), precision_digits=self.env.company.currency_id.decimal_places): + if not self.currency_id.is_zero(line_values.get('amount')): analytic_line_vals.append(line_values) return analytic_line_vals @@ -2735,7 +2735,8 @@ class AccountMoveLine(models.Model): account_id = int(account_id) account = self.env['account.analytic.account'].browse(account_id) distribution_plan = distribution_on_each_plan.get(account.root_plan_id, 0) + distribution - if self.env.company.currency_id.compare_amounts(distribution_plan, 100) == 0: + decimal_precision = self.env['decimal.precision'].precision_get('Percentage Analytic') + if float_compare(distribution_plan, 100, precision_digits=decimal_precision) == 0: amount = -self.balance * (100 - distribution_on_each_plan.get(account.root_plan_id, 0)) / 100.0 else: amount = -self.balance * distribution / 100.0