From 5af3cfc2b9ce648ae4aff69150266e4ad519050d Mon Sep 17 00:00:00 2001 From: "Dylan Kiss (dyki)" Date: Tue, 27 Feb 2024 13:17:47 +0000 Subject: [PATCH] [FIX] account_edi_ubl_cii: fix PriceAmount rounding In [1], we added a rounding of the amounts in the `` tags to avoid floating point rounding errors. However, it seems the `float_round` function does not guarantee to avoid these errors. Take the example of `price_subtotal` = 250.80 and `quantity` = 3. We will compute the PriceAmount as 250.80 / 3 which yields 83.60000000000001. Even when using `float_round(amount, 10)`, it still results in the same amount with the rounding error. For that reason we use the built-in `round` method of Python instead. [1] 58d57bbbaaab32ba0183890a9182e6de09b32ac5 closes odoo/odoo#156555 X-original-commit: 0b21d562fe4d315c01421b3f242e274830c34e79 Signed-off-by: Laurent Smet (las) Signed-off-by: Dylan Kiss (dyki) --- .../models/account_edi_xml_ubl_20.py | 3 +-- .../tests/test_xml_ubl_be.py | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py index 3bb75c72ff5..15538143c03 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py @@ -4,7 +4,6 @@ from lxml import etree from odoo import models, _ from odoo.tools import html2plaintext, cleanup_xml_node -from odoo.tools.float_utils import float_round class AccountEdiXmlUBL20(models.AbstractModel): @@ -338,7 +337,7 @@ class AccountEdiXmlUBL20(models.AbstractModel): 'currency_dp': self._get_currency_decimal_places(line.currency_id), # The price of an item, exclusive of VAT, after subtracting item price discount. - 'price_amount': float_round(gross_price_unit, 10), + 'price_amount': round(gross_price_unit, 10), 'product_price_dp': self.env['decimal.precision'].precision_get('Product Price'), # The number of item units to which the price applies. diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py index 6ee5c5b99c6..4f5127c07a7 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py @@ -527,15 +527,24 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon): self.partner_1, self.partner_2, move_type='out_invoice', - invoice_line_ids=[{ - 'product_id': self.product_a.id, - 'quantity': 3, - 'price_unit': 102.15, - 'tax_ids': [Command.set([self.tax_12.id])] - }], + invoice_line_ids=[ + { + 'product_id': self.product_a.id, + 'quantity': 3, + 'price_unit': 102.15, + 'tax_ids': [Command.set([self.tax_12.id])], + }, + { + 'product_id': self.product_a.id, + 'quantity': 3, + 'price_unit': 83.60, + 'tax_ids': [Command.set([self.tax_21.id])], + }, + ], ) - price_amount = etree.fromstring(invoice.ubl_cii_xml_id.raw).find('.//{*}InvoiceLine/{*}Price/{*}PriceAmount') - self.assertEqual(price_amount.text, '102.15') + price_amounts = etree.fromstring(invoice.ubl_cii_xml_id.raw).findall('.//{*}InvoiceLine/{*}Price/{*}PriceAmount') + self.assertEqual(price_amounts[0].text, '102.15') + self.assertEqual(price_amounts[1].text, '83.6') def test_export_tax_exempt(self): invoice = self._generate_move(