[FIX] account: round using line company instead of env

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) <wan@odoo.com>
Signed-off-by: Wala Gauthier (gawa) <gawa@odoo.com>
This commit is contained in:
gawa-odoo
2023-03-13 14:20:19 +01:00
parent 74109d0479
commit ae8bf42ca6
+4 -3
View File
@@ -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