From 1d34699aa9187bb30a8f32d4888f6ee7759b2c6b Mon Sep 17 00:00:00 2001 From: Camille Spiritus Date: Tue, 3 Jan 2023 13:28:18 +0000 Subject: [PATCH] [FIX] account: prevent tax info from being shown on invoice if only one tax Because of a faulty float comparison, additional taxes information would sometimes be uselessly displayed on invoices, specifically when only one tax was applied. Fixed said float comparison. Modified usage of built-in 'round' since check_style doesn't allow this anymore. closes odoo/odoo#109084 X-original-commit: 23a12c496cd7688b0021083bce2c84ce7ea2a3fb Signed-off-by: Laurent Smet --- addons/account/models/account_tax.py | 18 +++++++++--------- addons/sale/models/sale_order.py | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index e8e51c9dddf..f429629b087 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from odoo import api, fields, models, _, Command from odoo.osv import expression -from odoo.tools.float_utils import float_round as round +from odoo.tools.float_utils import float_round from odoo.exceptions import UserError, ValidationError from odoo.tools.misc import formatLang from odoo.tools import frozendict @@ -630,8 +630,8 @@ class AccountTax(models.Model): tax_base_amount, sign * price_unit, quantity, product, partner, fixed_multiplicator) # Round the tax_amount multiplied by the computed repartition lines factor. - tax_amount = round(tax_amount, precision_rounding=prec) - factorized_tax_amount = round(tax_amount * sum_repartition_factor, precision_rounding=prec) + tax_amount = float_round(tax_amount, precision_rounding=prec) + factorized_tax_amount = float_round(tax_amount * sum_repartition_factor, precision_rounding=prec) if price_include and total_included_checkpoints.get(i) is None: cumulated_tax_included_amount += factorized_tax_amount @@ -659,10 +659,10 @@ class AccountTax(models.Model): # The factorized_tax_amount will be 0.06 (200% x 0.03). However, each line taken independently will compute # 50% * 0.03 = 0.01 with rounding. It means there is 0.06 - 0.04 = 0.02 as total_rounding_error to dispatch # in lines as 2 x 0.01. - repartition_line_amounts = [round(tax_amount * line.factor, precision_rounding=prec) for line in tax_repartition_lines] - total_rounding_error = round(factorized_tax_amount - sum(repartition_line_amounts), precision_rounding=prec) + repartition_line_amounts = [float_round(tax_amount * line.factor, precision_rounding=prec) for line in tax_repartition_lines] + total_rounding_error = float_round(factorized_tax_amount - sum(repartition_line_amounts), precision_rounding=prec) nber_rounding_steps = int(abs(total_rounding_error / currency.rounding)) - rounding_error = round(nber_rounding_steps and total_rounding_error / nber_rounding_steps or 0.0, precision_rounding=prec) + rounding_error = float_round(nber_rounding_steps and total_rounding_error / nber_rounding_steps or 0.0, precision_rounding=prec) for repartition_line, line_amount in zip(tax_repartition_lines, repartition_line_amounts): @@ -679,7 +679,7 @@ class AccountTax(models.Model): 'id': tax.id, 'name': partner and tax.with_context(lang=partner.lang).name or tax.name, 'amount': sign * line_amount, - 'base': round(sign * tax_base_amount, precision_rounding=prec), + 'base': float_round(sign * tax_base_amount, precision_rounding=prec), 'sequence': tax.sequence, 'account_id': repartition_line._get_aml_target_tax_account().id, 'analytic': tax.analytic, @@ -1194,8 +1194,8 @@ class AccountTax(models.Model): amount_total = amount_untaxed + amount_tax - display_tax_base = (len(global_tax_details['tax_details']) == 1 and tax_group_vals_list[0]['base_amount'] != amount_untaxed) \ - or len(global_tax_details['tax_details']) > 1 + display_tax_base = (len(global_tax_details['tax_details']) == 1 and currency.compare_amounts(tax_group_vals_list[0]['base_amount'], amount_untaxed) != 0)\ + or len(global_tax_details['tax_details']) > 1 return { 'amount_untaxed': currency.round(amount_untaxed) if currency else amount_untaxed, diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 35b68807f73..24c08a96438 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -567,13 +567,13 @@ class SaleOrder(models.Model): order.partner_credit_warning = self.env['account.move']._build_credit_warning_message( order, updated_credit) - @api.depends('order_line.tax_id', 'order_line.price_unit', 'amount_total', 'amount_untaxed') + @api.depends('order_line.tax_id', 'order_line.price_unit', 'amount_total', 'amount_untaxed', 'currency_id') def _compute_tax_totals(self): for order in self: order_lines = order.order_line.filtered(lambda x: not x.display_type) order.tax_totals = self.env['account.tax']._prepare_tax_totals( [x._convert_to_tax_base_line_dict() for x in order_lines], - order.currency_id, + order.currency_id or order.company_id.currency_id, ) @api.depends('state')