From 0bb419cf118c8d01b2b4f541b39e7cc5115e1a54 Mon Sep 17 00:00:00 2001 From: Julien Van Roy Date: Fri, 7 Jul 2023 09:59:17 +0000 Subject: [PATCH] [FIX] account_edi_ubl_cii: import with missing unit prices Sometimes, the net price and the gross price are not present in the invoice line, but the line subtotal is (for instance, with some xml from Billit). In this case, it is still possible to infer the Odoo unit price and parse the xml correctly. opw-3384704 closes odoo/odoo#128338 X-original-commit: a8c82e6e4e47d951601364f1714a4150fa63f62a Signed-off-by: Laurent Smet (las) Signed-off-by: Julien Van Roy (juvr) --- .../i18n/account_edi_ubl_cii.pot | 3 +- .../models/account_edi_common.py | 4 +- .../from_odoo/bis3_out_invoice_no_prices.xml | 168 ++++++++++++++++++ .../tests/test_xml_ubl_be.py | 14 +- 4 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 addons/l10n_account_edi_ubl_cii_tests/tests/test_files/from_odoo/bis3_out_invoice_no_prices.xml diff --git a/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot b/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot index 2873c152f99..6d9c1565513 100644 --- a/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot +++ b/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot @@ -686,7 +686,8 @@ msgstr "" #. odoo-python #: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0 #, python-format -msgid "No gross price nor net price found for line in xml" +msgid "" +"No gross price, net price nor line subtotal amount found for line in xml" msgstr "" #. module: account_edi_ubl_cii diff --git a/addons/account_edi_ubl_cii/models/account_edi_common.py b/addons/account_edi_ubl_cii/models/account_edi_common.py index f096a6ae63e..34601565af8 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_common.py +++ b/addons/account_edi_ubl_cii/models/account_edi_common.py @@ -621,8 +621,10 @@ class AccountEdiCommon(models.AbstractModel): price_unit = gross_price_unit / basis_qty elif net_price_unit is not None: price_unit = (net_price_unit + rebate) / basis_qty + elif price_subtotal is not None: + price_unit = (price_subtotal + allow_charge_amount) / billed_qty else: - raise UserError(_("No gross price nor net price found for line in xml")) + raise UserError(_("No gross price, net price nor line subtotal amount found for line in xml")) # discount discount = 0 diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_files/from_odoo/bis3_out_invoice_no_prices.xml b/addons/l10n_account_edi_ubl_cii_tests/tests/test_files/from_odoo/bis3_out_invoice_no_prices.xml new file mode 100644 index 00000000000..6936362d26e --- /dev/null +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_files/from_odoo/bis3_out_invoice_no_prices.xml @@ -0,0 +1,168 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + INV/2017/01/0002 + 2017-01-01 + 2017-02-28 + 380 + test narration + USD + ref_partner_2 + + ref_move + + + + BE0202239951 + + partner_1 + + + Chaussée de Namur 40 + Ramillies + 1367 + + BE + + + + BE0202239951 + + VAT + + + + partner_1 + BE0202239951 + + + partner_1 + + + + + + BE0477472701 + + partner_2 + + + Rue des Bourlottes 9 + Ramillies + 1367 + + BE + + + + BE0477472701 + + VAT + + + + partner_2 + BE0477472701 + + + partner_2 + + + + + 30 + +++000/0000/26268+++ + + BE15001559627230 + + + + 30% Advance End of Following Month + + + 482.22 + + 1782.00 + 374.22 + + S + 21.0 + + VAT + + + + + 900.00 + 108.00 + + S + 12.0 + + VAT + + + + + + 2682.00 + 2682.00 + 3164.22 + 0.00 + 3164.22 + + + 901 + 2.0 + 1782.00 + + false + 95 + 198.00 + + + product_a + product_a + + S + 21.0 + + VAT + + + + + + 902 + 10.0 + 1000.00 + + product_b + product_b + + S + 12.0 + + VAT + + + + + + 903 + -1.0 + -100.00 + + product_b + product_b + + S + 12.0 + + VAT + + + + + 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 c47643e6598..798b41dfccc 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 @@ -442,8 +442,18 @@ class TestUBLBE(TestUBLCommon, TestAccountMoveSendCommon): self.assertTrue(created_bill) def test_import_invoice_xml(self): - self._assert_imported_invoice_from_file(subfolder='tests/test_files/from_odoo', filename='bis3_out_invoice.xml', - amount_total=3164.22, amount_tax=482.22, list_line_subtotals=[1782, 1000, -100], currency_id=self.currency_data['currency'].id) + kwargs = { + 'subfolder': 'tests/test_files/from_odoo', + 'amount_total': 3164.22, + 'amount_tax': 482.22, + 'list_line_subtotals': [1782, 1000, -100], + 'list_line_price_unit': [990, 100, 100], + 'list_line_discount': [10, 0, 0], + 'currency_id': self.currency_data['currency'].id, + } + self._assert_imported_invoice_from_file(filename='bis3_out_invoice.xml', **kwargs) + # same as the file above, but the are missing in the invoice lines + self._assert_imported_invoice_from_file(filename='bis3_out_invoice_no_prices.xml', **kwargs) def test_import_invoice_xml_open_peppol_examples(self): # Source: https://github.com/OpenPEPPOL/peppol-bis-invoice-3/tree/master/rules/examples