From 340f6fe1c30aeb9fe1ce7d3d752ae18c0e0df589 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 25 Dec 2025 11:50:40 +0100 Subject: [PATCH 01/11] [ADD] account_edi_ubl_cii_retrieve_tax Match taxes on UBL import using UNECE tax codes --- account_edi_ubl_cii_retrieve_tax/README.rst | 90 ++++ account_edi_ubl_cii_retrieve_tax/__init__.py | 1 + .../__manifest__.py | 15 + .../models/__init__.py | 1 + .../models/account_edi_xml_ubl_20.py | 115 +++++ .../readme/CONTRIBUTORS.md | 1 + .../readme/DESCRIPTION.md | 3 + .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/index.html | 428 ++++++++++++++++++ .../tests/__init__.py | 1 + .../test_account_edi_ubl_cii_retrieve_tax.py | 146 ++++++ .../tests/test_files/bis3_bill_example.xml | 144 ++++++ .../test_files/bis3_bill_k_vatex_eu_ic.xml | 147 ++++++ .../tests/test_files/bis3_bill_no_code.xml | 142 ++++++ .../tests/test_files/bis3_bill_not_vat.xml | 144 ++++++ .../addons/account_edi_ubl_cii_retrieve_tax | 1 + .../account_edi_ubl_cii_retrieve_tax/setup.py | 6 + 17 files changed, 1385 insertions(+) create mode 100644 account_edi_ubl_cii_retrieve_tax/README.rst create mode 100644 account_edi_ubl_cii_retrieve_tax/__init__.py create mode 100644 account_edi_ubl_cii_retrieve_tax/__manifest__.py create mode 100644 account_edi_ubl_cii_retrieve_tax/models/__init__.py create mode 100644 account_edi_ubl_cii_retrieve_tax/models/account_edi_xml_ubl_20.py create mode 100644 account_edi_ubl_cii_retrieve_tax/readme/CONTRIBUTORS.md create mode 100644 account_edi_ubl_cii_retrieve_tax/readme/DESCRIPTION.md create mode 100644 account_edi_ubl_cii_retrieve_tax/static/description/icon.png create mode 100644 account_edi_ubl_cii_retrieve_tax/static/description/index.html create mode 100644 account_edi_ubl_cii_retrieve_tax/tests/__init__.py create mode 100644 account_edi_ubl_cii_retrieve_tax/tests/test_account_edi_ubl_cii_retrieve_tax.py create mode 100644 account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_example.xml create mode 100644 account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_k_vatex_eu_ic.xml create mode 100644 account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_no_code.xml create mode 100644 account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_not_vat.xml create mode 120000 setup/account_edi_ubl_cii_retrieve_tax/odoo/addons/account_edi_ubl_cii_retrieve_tax create mode 100644 setup/account_edi_ubl_cii_retrieve_tax/setup.py diff --git a/account_edi_ubl_cii_retrieve_tax/README.rst b/account_edi_ubl_cii_retrieve_tax/README.rst new file mode 100644 index 0000000000..65ee3a6a76 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/README.rst @@ -0,0 +1,90 @@ +================================ +Account Edi Ubl Cii Retrieve Tax +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:72b354e23f18ad219d7c55dcd6abbb601278193ffe5d32aea0b2fbe72da37b78 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github + :target: https://github.com/OCA/edi/tree/16.0/account_edi_ubl_cii_retrieve_tax + :alt: OCA/edi +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_edi_ubl_cii_retrieve_tax + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon improves UBL invoice import by matching taxes using the UNECE +tax category/code instead of relying on rates, ensuring more accurate +and consistent tax retrieval across companies and localizations. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV +* BCIM + +Contributors +------------ + +- Souheil Bejaoui souheil.bejaoui@acsone.eu + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px + :target: https://github.com/sbejaoui + :alt: sbejaoui +.. |maintainer-jbaudoux| image:: https://github.com/jbaudoux.png?size=40px + :target: https://github.com/jbaudoux + :alt: jbaudoux + +Current `maintainers `__: + +|maintainer-sbejaoui| |maintainer-jbaudoux| + +This module is part of the `OCA/edi `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_edi_ubl_cii_retrieve_tax/__init__.py b/account_edi_ubl_cii_retrieve_tax/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_edi_ubl_cii_retrieve_tax/__manifest__.py b/account_edi_ubl_cii_retrieve_tax/__manifest__.py new file mode 100644 index 0000000000..2dfb84465a --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2026 ACSONE SA/NV,BCIM +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Edi Ubl Cii Retrieve Tax", + "summary": """Match taxes on UBL import using UNECE tax codes""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,BCIM,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/edi", + "depends": ["account_edi_ubl_cii", "account_edi_ubl_cii_tax_extension"], + "data": [], + "demo": [], + "maintainers": ["sbejaoui", "jbaudoux"], +} diff --git a/account_edi_ubl_cii_retrieve_tax/models/__init__.py b/account_edi_ubl_cii_retrieve_tax/models/__init__.py new file mode 100644 index 0000000000..bb546b5d27 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/models/__init__.py @@ -0,0 +1 @@ +from . import account_edi_xml_ubl_20 diff --git a/account_edi_ubl_cii_retrieve_tax/models/account_edi_xml_ubl_20.py b/account_edi_ubl_cii_retrieve_tax/models/account_edi_xml_ubl_20.py new file mode 100644 index 0000000000..e4a2e3c4a3 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/models/account_edi_xml_ubl_20.py @@ -0,0 +1,115 @@ +# Copyright 2026 ACSONE SA/NV,BCIM +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.osv.expression import AND + + +class AccountEdiXmlUBL20(models.AbstractModel): + _inherit = "account.edi.xml.ubl_20" + + def _get_tax_exemption_reason_code(self, tax_exemption_reason_code): + """ + Map a UBL tax exemption reason code to a valid selection key for + ubl_cii_tax_exemption_reason_code field + + handles formatting differences (e.g. '_' vs '-') by trying normalized + variants of the input code + + :return: matching selection key or False if not found + """ + tax_exemption_reason_codes = dict( + self.env["account.tax"] + ._fields.get("ubl_cii_tax_exemption_reason_code") + .selection + ) + if tax_exemption_reason_codes.get(tax_exemption_reason_code): + return tax_exemption_reason_code + if tax_exemption_reason_codes.get(tax_exemption_reason_code.replace("-", "_")): + return tax_exemption_reason_code.replace("-", "_") + if tax_exemption_reason_codes.get(tax_exemption_reason_code.replace("_", "-")): + return tax_exemption_reason_code.replace("_", "-") + return False + + def _import_fill_invoice_line_form( + self, journal, tree, invoice, invoice_line, qty_factor + ): + res = super()._import_fill_invoice_line_form( + journal, tree, invoice, invoice_line, qty_factor + ) + if journal.type != "purchase" or len(invoice_line.tax_ids) > 1: + # this addon targets purchase imports only + # UBL are expected to produce a single tax per line, if multiple taxes + # were already assigned, keep the standard result to avoid unexpected + # changes + return res + tax_type = tree.find(".//{*}Item/{*}ClassifiedTaxCategory/{*}TaxScheme/{*}ID") + if tax_type is None or not tax_type.text or tax_type.text.upper() != "VAT": + return res + tax_unece_code_node = tree.find(".//{*}Item/{*}ClassifiedTaxCategory/{*}ID") + tax_exemption_reason_code_node = tree.find( + ".//{*}Item/{*}ClassifiedTaxCategory/{*}TaxExemptionReasonCode" + ) + tax_exemption_reason_code = False + if tax_exemption_reason_code_node is not None: + tax_exemption_reason_code = self._get_tax_exemption_reason_code( + tax_exemption_reason_code_node.text + ) + tax_amount_node = tree.find(".//{*}Item/{*}ClassifiedTaxCategory/{*}Percent") + if tax_amount_node is None or tax_unece_code_node is None: + # stop if the file doesn't provide the UNECE tax code + return res + amount = float(tax_amount_node.text) + tax_unece_code = tax_unece_code_node.text + if ( + invoice_line.tax_ids.amount == amount + and invoice_line.tax_ids.ubl_cii_tax_category_code == tax_unece_code + and invoice_line.tax_ids.ubl_cii_tax_exemption_reason_code + == tax_exemption_reason_code + ): + # stop if the result already matches the UNECE code + return res + taxes = self._get_tax_by_ubl_values( + journal, + amount, + tax_unece_code, + tax_exemption_reason_code=tax_exemption_reason_code, + invoice_line=invoice_line, + ) + if taxes: + invoice_line.tax_ids = taxes[0] + return res + + def _get_tax_by_ubl_values( + self, journal, amount, tax_unece_code, tax_exemption_reason_code=False, **kwargs + ): + return self.env["account.tax"].search( + self._get_tax_by_ubl_values_domain( + journal, amount, tax_unece_code, tax_exemption_reason_code + ) + ) + + def _get_tax_by_ubl_values_domain( + self, journal, amount, tax_unece_code, tax_exemption_reason_code=False + ): + domain = [ + ("company_id", "=", journal.company_id.id), + ("amount_type", "=", "percent"), + ("type_tax_use", "=", journal.type), + ("ubl_cii_tax_category_code", "=", tax_unece_code), + ("amount", "=", amount), + ] + if tax_exemption_reason_code: + domain = AND( + [ + domain, + [ + ( + "ubl_cii_tax_exemption_reason_code", + "=", + tax_exemption_reason_code, + ) + ], + ] + ) + return domain diff --git a/account_edi_ubl_cii_retrieve_tax/readme/CONTRIBUTORS.md b/account_edi_ubl_cii_retrieve_tax/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..b9a2f0a4d2 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui \ No newline at end of file diff --git a/account_edi_ubl_cii_retrieve_tax/readme/DESCRIPTION.md b/account_edi_ubl_cii_retrieve_tax/readme/DESCRIPTION.md new file mode 100644 index 0000000000..3ad0359dfc --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This addon improves UBL invoice import by matching taxes using the UNECE tax +category/code instead of relying on rates, ensuring more accurate and +consistent tax retrieval across companies and localizations. diff --git a/account_edi_ubl_cii_retrieve_tax/static/description/icon.png b/account_edi_ubl_cii_retrieve_tax/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW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TTL&!?O+%Rv;b?B??gSzdp?6Uug9{ zd@V08Z$BdI?fpoCS$)t4mg4rT8Q_I}h`0d-vYZ^|dOB*Q^S|xqTV*vIg?@fVFSmMpaw0qtTRbx} z({Pg?#{2`sc9)M5N$*N|4;^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/account_edi_ubl_cii_retrieve_tax/static/description/index.html b/account_edi_ubl_cii_retrieve_tax/static/description/index.html new file mode 100644 index 0000000000..d7a59819c2 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +Account Edi Ubl Cii Retrieve Tax + + + +
+

Account Edi Ubl Cii Retrieve Tax

+ + +

Beta License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runboat

+

This addon improves UBL invoice import by matching taxes using the UNECE +tax category/code instead of relying on rates, ensuring more accurate +and consistent tax retrieval across companies and localizations.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
  • BCIM
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainers:

+

sbejaoui jbaudoux

+

This module is part of the OCA/edi project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_edi_ubl_cii_retrieve_tax/tests/__init__.py b/account_edi_ubl_cii_retrieve_tax/tests/__init__.py new file mode 100644 index 0000000000..4e666024c0 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_edi_ubl_cii_retrieve_tax diff --git a/account_edi_ubl_cii_retrieve_tax/tests/test_account_edi_ubl_cii_retrieve_tax.py b/account_edi_ubl_cii_retrieve_tax/tests/test_account_edi_ubl_cii_retrieve_tax.py new file mode 100644 index 0000000000..e2d529de51 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/tests/test_account_edi_ubl_cii_retrieve_tax.py @@ -0,0 +1,146 @@ +# Copyright 2026 ACSONE SA/NV,BCIM +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo.tests import tagged +from odoo.tools import file_open + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + +TEST_FILES_DIR = "account_edi_ubl_cii_retrieve_tax/tests/test_files" + + +@tagged("post_install", "-at_install") +class TestAccountEdiUblCiiRetrieveTax(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass() + cls.tax_33_no_code = cls.env["account.tax"].create( + { + "name": "33% no code", + "type_tax_use": "purchase", + "amount_type": "percent", + "amount": 33, + "sequence": 10, + } + ) + cls.tax_33_code_s = cls.env["account.tax"].create( + { + "name": "33%", + "type_tax_use": "purchase", + "amount_type": "percent", + "amount": 33, + "sequence": 100, + "ubl_cii_tax_category_code": "S", + } + ) + cls.tax_33_code_k_no_reason = cls.env["account.tax"].create( + { + "name": "21% K", + "type_tax_use": "purchase", + "amount_type": "percent", + "amount": 33, + "sequence": 110, + "ubl_cii_tax_category_code": "K", + } + ) + cls.tax_33_code_k = cls.env["account.tax"].create( + { + "name": "21% K", + "type_tax_use": "purchase", + "amount_type": "percent", + "amount": 33, + "sequence": 110, + "ubl_cii_tax_category_code": "K", + "ubl_cii_tax_exemption_reason_code": "VATEX_EU_IC", + } + ) + + def _import_invoice(self, journal, file_name=None): + if not file_name: + file_name = "bis3_bill_example.xml" + file_path = f"{TEST_FILES_DIR}/{file_name}" + with file_open(file_path, "rb") as file: + xml_attachment = self.env["ir.attachment"].create( + { + "mimetype": "application/xml", + "name": "test_invoice.xml", + "raw": file.read(), + } + ) + move = ( + self.env["account.journal"] + .with_context(default_journal_id=journal.id) + ._create_document_from_attachment(xml_attachment.id) + ) + return move + + def test_0(self): + """ + default behavior + If no ubl_cii_tax_category_code, take the first tax that match the amount and type + """ + self.tax_33_code_s.ubl_cii_tax_category_code = False + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.tax_ids, self.tax_33_no_code) + + def test_1(self): + """ + match tax by unece_categ code + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.tax_ids, self.tax_33_code_s) + + def test_2(self): + """ + match tax by unece code + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.tax_ids, self.tax_33_code_s) + + def test_3(self): + """ + no unece code in the file + """ + bill = self._import_invoice( + self.company_data["default_journal_purchase"], "bis3_bill_no_code.xml" + ) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.tax_ids, self.tax_33_no_code) + + def test_4(self): + """ + no change in sale behavior + """ + bill = self._import_invoice( + self.company_data["default_journal_sale"], "bis3_bill_example.xml" + ) + inv_line = bill.invoice_line_ids + self.assertNotEqual(inv_line.tax_ids, self.tax_33_no_code) + + def test_5(self): + """ + default behavior if tax type is not vat + """ + bill = self._import_invoice( + self.company_data["default_journal_purchase"], "bis3_bill_not_vat.xml" + ) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.tax_ids, self.tax_33_no_code) + + def test_6(self): + """ + import with exemption reason + """ + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + "bis3_bill_k_vatex_eu_ic.xml", + ) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.tax_ids, self.tax_33_code_k) + self.assertEqual( + inv_line.tax_ids.ubl_cii_tax_exemption_reason_code, "VATEX_EU_IC" + ) diff --git a/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_example.xml b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_example.xml new file mode 100644 index 0000000000..774103850f --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_example.xml @@ -0,0 +1,144 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 105.12 + + 657.00 + 105.12 + + S + 33.0 + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + S + 33.0 + + VAT + + + + + 657.00 + + + diff --git a/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_k_vatex_eu_ic.xml b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_k_vatex_eu_ic.xml new file mode 100644 index 0000000000..73244c50db --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_k_vatex_eu_ic.xml @@ -0,0 +1,147 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 0.00 + + 657.00 + 0.00 + + K + 33 + VATEX-EU-IC + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + K + 33 + VATEX-EU-IC + + VAT + + + + + 657.00 + + + diff --git a/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_no_code.xml b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_no_code.xml new file mode 100644 index 0000000000..89fa9daa5b --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_no_code.xml @@ -0,0 +1,142 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 105.12 + + 657.00 + 105.12 + + 33.0 + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + 33.0 + + VAT + + + + + 657.00 + + + diff --git a/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_not_vat.xml b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_not_vat.xml new file mode 100644 index 0000000000..8e75d75386 --- /dev/null +++ b/account_edi_ubl_cii_retrieve_tax/tests/test_files/bis3_bill_not_vat.xml @@ -0,0 +1,144 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 105.12 + + 657.00 + 105.12 + + S + 33.0 + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + S + 33.0 + + NOT VAT + + + + + 657.00 + + + diff --git a/setup/account_edi_ubl_cii_retrieve_tax/odoo/addons/account_edi_ubl_cii_retrieve_tax b/setup/account_edi_ubl_cii_retrieve_tax/odoo/addons/account_edi_ubl_cii_retrieve_tax new file mode 120000 index 0000000000..ab2e3a1f01 --- /dev/null +++ b/setup/account_edi_ubl_cii_retrieve_tax/odoo/addons/account_edi_ubl_cii_retrieve_tax @@ -0,0 +1 @@ +../../../../account_edi_ubl_cii_retrieve_tax \ No newline at end of file diff --git a/setup/account_edi_ubl_cii_retrieve_tax/setup.py b/setup/account_edi_ubl_cii_retrieve_tax/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/account_edi_ubl_cii_retrieve_tax/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 8f57ab3a153b9033a086aad81d3fef555cfbcba5 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 22 Dec 2025 17:34:37 +0100 Subject: [PATCH 02/11] [ADD] account_edi_ubl_cii_purchase_match Extend UBL vendor bill import to automatically match and link bill lines to purchase order lines using the OrderReference and product label [IMP] account_edi_ubl_cii_purchase_match: show price_subtotal in purchase line form view [FIX] account_edi_ubl_cii_purchase_match: allow to change po line [FIX] account_edi_ubl_cii_purchase_match: don't update supplier info product name [FIX] account_edi_ubl_cii_purchase_match: match po only if order_ref is set --- account_edi_ubl_cii_purchase_match/README.rst | 178 ++++++ .../__init__.py | 2 + .../__manifest__.py | 20 + .../account_edi_ubl_cii_purchase_match.pot | 242 ++++++++ account_edi_ubl_cii_purchase_match/i18n/fr.po | 252 +++++++++ .../models/__init__.py | 3 + .../models/account_edi_xml_ubl_20.py | 150 +++++ .../models/account_move.py | 57 ++ .../models/account_move_line.py | 147 +++++ .../readme/CONFIGURE.md | 12 + .../readme/CONTEXT.md | 12 + .../readme/CONTRIBUTORS.md | 1 + .../readme/DESCRIPTION.md | 20 + .../readme/ROADMAP.md | 10 + .../readme/USAGE.md | 11 + ..._move_line_select_purchase_line_wizard.xml | 24 + .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/index.html | 526 ++++++++++++++++++ .../tests/__init__.py | 1 + ...test_account_edi_ubl_cii_purchase_match.py | 292 ++++++++++ .../tests/test_files/bis3_bill_example.xml | 144 +++++ ...is3_bill_example_invoiced_qty_mismatch.xml | 144 +++++ .../bis3_bill_example_price_unit_mismatch.xml | 144 +++++ .../views/account_move.xml | 51 ++ .../views/purchase_order_line.xml | 72 +++ .../wizards/__init__.py | 1 + ...t_move_line_select_purchase_line_wizard.py | 78 +++ ..._move_line_select_purchase_line_wizard.xml | 63 +++ .../addons/account_edi_ubl_cii_purchase_match | 1 + .../setup.py | 6 + 30 files changed, 2664 insertions(+) create mode 100644 account_edi_ubl_cii_purchase_match/README.rst create mode 100644 account_edi_ubl_cii_purchase_match/__init__.py create mode 100644 account_edi_ubl_cii_purchase_match/__manifest__.py create mode 100644 account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot create mode 100644 account_edi_ubl_cii_purchase_match/i18n/fr.po create mode 100644 account_edi_ubl_cii_purchase_match/models/__init__.py create mode 100644 account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py create mode 100644 account_edi_ubl_cii_purchase_match/models/account_move.py create mode 100644 account_edi_ubl_cii_purchase_match/models/account_move_line.py create mode 100644 account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md create mode 100644 account_edi_ubl_cii_purchase_match/readme/CONTEXT.md create mode 100644 account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md create mode 100644 account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md create mode 100644 account_edi_ubl_cii_purchase_match/readme/ROADMAP.md create mode 100644 account_edi_ubl_cii_purchase_match/readme/USAGE.md create mode 100644 account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml create mode 100644 account_edi_ubl_cii_purchase_match/static/description/icon.png create mode 100644 account_edi_ubl_cii_purchase_match/static/description/index.html create mode 100644 account_edi_ubl_cii_purchase_match/tests/__init__.py create mode 100644 account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py create mode 100644 account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml create mode 100644 account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml create mode 100644 account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml create mode 100644 account_edi_ubl_cii_purchase_match/views/account_move.xml create mode 100644 account_edi_ubl_cii_purchase_match/views/purchase_order_line.xml create mode 100644 account_edi_ubl_cii_purchase_match/wizards/__init__.py create mode 100644 account_edi_ubl_cii_purchase_match/wizards/account_move_line_select_purchase_line_wizard.py create mode 100644 account_edi_ubl_cii_purchase_match/wizards/account_move_line_select_purchase_line_wizard.xml create mode 120000 setup/account_edi_ubl_cii_purchase_match/odoo/addons/account_edi_ubl_cii_purchase_match create mode 100644 setup/account_edi_ubl_cii_purchase_match/setup.py diff --git a/account_edi_ubl_cii_purchase_match/README.rst b/account_edi_ubl_cii_purchase_match/README.rst new file mode 100644 index 0000000000..6cb9250be6 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/README.rst @@ -0,0 +1,178 @@ +================================== +Account Edi Ubl Cii Purchase Match +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1108f90b17102bd7717d78746240a8d5c4a572e692d8ccb94fc16b84e1a9785d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github + :target: https://github.com/OCA/edi/tree/16.0/account_edi_ubl_cii_purchase_match + :alt: OCA/edi +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_edi_ubl_cii_purchase_match + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the UBL vendor bill import process to improve how +vendor bill lines are linked to purchase order lines. + +Instead of replacing the imported UBL lines with the purchase order +lines (standard behavior), this module: + +1. **Reads the OrderReference** in the UBL document. + +2. **Identifies the corresponding Purchase Order** using the vendor + reference (``partner_ref``) or the purchase order ref. + +3. **Matches each UBL line** with a purchase order line based on: + + - product name, + - supplier product name + +4. **Links the vendor bill line** to the matched PO line + +5. When a user manually selects a purchase order line from the bill: + + - the system stores the supplier product name, + - future imports will auto-match using that supplier information. + +This ensures accurate line-level linking while preserving the supplier’s +invoice data. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +In the standard behavior, when importing a vendor bill from a UBL +document: + +- If a Purchase Order is found, **all imported UBL lines are replaced** + by the Purchase Order lines. +- This causes a **loss of original UBL data**, such as: + + - line-level descriptions, + - quantities, + - pricing, + - tax information received from the supplier. + +- Additionally, the standard flow performs **no matching based on + product labels**, so incorrect PO lines may be added if PO content + does not reflect what is actually on the invoice. + +Configuration +============= + +No configuration is required to use this module. + +However, for optimal matching: + +- Ensure that *OrderReference* in the vendor UBL document corresponds to + the Purchase Order Ref or the **Vendor Reference** (``partner_ref``). +- Maintain consistent **product names** or **supplier product names** so + that UBL line descriptions can be matched to the correct purchase + order line. + +Optional but recommended: + +- Define supplier product names (``product.supplierinfo``) to improve + matching accuracy. + +Usage +===== + +1. Import a vendor bill in UBL format through: Accounting / Vendors / + Bills / Upload +2. The module will automatically: + + - Extract the OrderReference from the UBL. + - Find the matching purchase order via ``partner_ref`` or purchase + order ref. + - Attempt to match each UBL line with the correct purchase order line + using: + + - product name, + - supplier product name + +3. When a match is found: the vendor bill line is linked to the purchase + order line. +4. If no match is found: + + - Click "Select purchase line" button in invoice line + - Select a purchase order and a purchase order line + +Known issues / Roadmap +====================== + +This module implements custom purchase order line matching and replaces +the standard behavior of linking vendor bills to purchase orders via +UBL. + +Before migrating to future versions, it is recommended to verify +whether: + +- Odoo natively supports precise line-level matching, +- supplier product names and UBL descriptions are matched out of the + box, +- and the original UBL lines are preserved. + +If the standard behavior evolves to fully cover this business +requirement, this module may become unnecessary. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Souheil Bejaoui souheil.bejaoui@acsone.eu + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/edi `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_edi_ubl_cii_purchase_match/__init__.py b/account_edi_ubl_cii_purchase_match/__init__.py new file mode 100644 index 0000000000..aee8895e7a --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/account_edi_ubl_cii_purchase_match/__manifest__.py b/account_edi_ubl_cii_purchase_match/__manifest__.py new file mode 100644 index 0000000000..de9a3a0d5d --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Edi Ubl Cii Purchase Match", + "summary": """Extend UBL vendor bill import to automatically match and link bill + lines to purchase order lines using the OrderReference and product label.""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/edi", + "depends": ["account_edi_ubl_cii", "purchase"], + "data": [ + "security/account_move_line_select_purchase_line_wizard.xml", + "wizards/account_move_line_select_purchase_line_wizard.xml", + "views/account_move.xml", + "views/purchase_order_line.xml", + ], + "demo": [], +} diff --git a/account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot b/account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot new file mode 100644 index 0000000000..d281149af8 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot @@ -0,0 +1,242 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_edi_ubl_cii_purchase_match +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-09 13:50+0000\n" +"PO-Revision-Date: 2025-12-09 13:50+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Invoiced quantity exceeds the ordered quantity." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Unit price differs from the purchase order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__qty_invoiced +msgid "Billed Qty" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Cancel" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "" +"Checked when this invoice has at least one line that does not fully match " +"its related purchase order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "" +"Checked when this invoice line does not fully match its related purchase " +"order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Close" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_uid +msgid "Created by" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_date +msgid "Created on" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__display_name +msgid "Display Name" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "" +"Human-readable description of the differences between invoice lines and " +"their related purchase order lines." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "" +"Human-readable description of the differences between this invoice line and " +"the related purchase order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__id +msgid "ID" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Invoice" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__description +msgid "Label" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_date +msgid "Last Updated on" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_line_id +msgid "Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_id +msgid "Move Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "No product" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_uom_qty +msgid "Ordered Qty" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__partner_id +msgid "Partner" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_id +msgid "Product" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_domain +msgid "Product Domain" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +msgid "Purchase Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "Purchase Line Mismatch" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "Purchase Line Mismatch Details" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "Purchase Mismatch" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "Purchase Mismatch Details" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_id +msgid "Purchase Order" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__qty_received +msgid "Received Qty" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +msgid "Select Purchase Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Select The Purchase Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__supplier_product_code +msgid "Supplier Product Code" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "" +"The following differences were detected between this invoice and its related" +" purchase order lines:\n" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_edi_xml_ubl_20 +msgid "UBL 2.0" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line_select_purchase_line_wizard +msgid "account move line select purchase line wizard" +msgstr "" diff --git a/account_edi_ubl_cii_purchase_match/i18n/fr.po b/account_edi_ubl_cii_purchase_match/i18n/fr.po new file mode 100644 index 0000000000..4cfccb9766 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/i18n/fr.po @@ -0,0 +1,252 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_edi_ubl_cii_purchase_match +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-09 13:50+0000\n" +"PO-Revision-Date: 2025-12-09 13:50+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Invoiced quantity exceeds the ordered quantity." +msgstr "- La quantité facturée dépasse la quantité commandée." + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Unit price differs from the purchase order line." +msgstr "- Le prix unitaire diffère de celui de la ligne de commande." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__qty_invoiced +msgid "Billed Qty" +msgstr "Qté facturée" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Cancel" +msgstr "Annuler" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "" +"Checked when this invoice has at least one line that does not fully match " +"its related purchase order line." +msgstr "" +"Coché lorsque cette facture comporte au moins une ligne ne correspondant pas " +"entièrement à sa ligne de commande d'achat associée." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "" +"Checked when this invoice line does not fully match its related purchase " +"order line." +msgstr "" +"Coché lorsque cette ligne de facture ne correspond pas entièrement à sa " +"ligne de commande d'achat." + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Close" +msgstr "Fermer" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_uid +msgid "Created by" +msgstr "Créé par" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_date +msgid "Created on" +msgstr "Créé le" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "" +"Human-readable description of the differences between invoice lines and " +"their related purchase order lines." +msgstr "" +"Description des différences entre les lignes de facture et leurs " +"lignes de commande d'achat associées." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "" +"Human-readable description of the differences between this invoice line and " +"the related purchase order line." +msgstr "" +"Description des différences entre cette ligne de facture et la ligne " +"de commande d'achat correspondante." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__id +msgid "ID" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Invoice" +msgstr "Facture" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move +msgid "Journal Entry" +msgstr "Écriture de journal" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line +msgid "Journal Item" +msgstr "Ecriture comptable" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__description +msgid "Label" +msgstr "Libellé" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_uid +msgid "Last Updated by" +msgstr "Modifié par" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_date +msgid "Last Updated on" +msgstr "Modifié le" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_line_id +msgid "Line" +msgstr "Ligne" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_id +msgid "Move Line" +msgstr "Ligne d'écriture" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "No product" +msgstr "Aucun produit" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_uom_qty +msgid "Ordered Qty" +msgstr "Qté Commandée" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__partner_id +msgid "Partner" +msgstr "Partenaire" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_id +msgid "Product" +msgstr "Produit" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_domain +msgid "Product Domain" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +msgid "Purchase Line" +msgstr "Ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "Purchase Line Mismatch" +msgstr "Incohérence ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "Purchase Line Mismatch Details" +msgstr "Détails de l'incohérence ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "Purchase Mismatch" +msgstr "Incohérence d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "Purchase Mismatch Details" +msgstr "Détails de l'incohérence d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_id +msgid "Purchase Order" +msgstr "Commande d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__qty_received +msgid "Received Qty" +msgstr "Qté reçue" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +msgid "Select Purchase Line" +msgstr "Sélectionner une ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Select The Purchase Line" +msgstr "Sélectionner La ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__supplier_product_code +msgid "Supplier Product Code" +msgstr "Référence produit fournisseur" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "" +"The following differences were detected between this invoice and its related" +" purchase order lines:\n" +msgstr "" +"Les différences suivantes ont été détectées entre cette facture et ses " +"lignes de commande d'achat associées :\n" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_edi_xml_ubl_20 +msgid "UBL 2.0" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line_select_purchase_line_wizard +msgid "account move line select purchase line wizard" +msgstr "" \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/models/__init__.py b/account_edi_ubl_cii_purchase_match/models/__init__.py new file mode 100644 index 0000000000..7a5c2f77f1 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_edi_xml_ubl_20 +from . import account_move +from . import account_move_line diff --git a/account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py b/account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py new file mode 100644 index 0000000000..52de5203fe --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py @@ -0,0 +1,150 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountEdiXmlUBL20(models.AbstractModel): + + _inherit = "account.edi.xml.ubl_20" + + def _import_fill_invoice_form(self, journal, tree, invoice, qty_factor): + """ + automatically match the invoice with a purchase order + + - disable standard purchase matching to avoid conflicts + - only apply for vendor bills + - use invoice_origin (UBL OrderReference) to find the related PO + """ + invoice = invoice.with_context(no_purchase_set=True) + res = super()._import_fill_invoice_form(journal, tree, invoice, qty_factor) + if journal.type != "purchase": + return res + if not invoice.invoice_origin: + return res + self._match_invoice_to_purchase_order(invoice, invoice.invoice_origin) + return res + + def _match_invoice_to_purchase_order(self, invoice, order_ref): + """ + match the invoice with a purchase order using the order ref + + matching is done on: + - PO name + - Vendor reference (partner_ref) + -o nly confirmed POs are considered + """ + purchase_order = self.env["purchase.order"].search( + [ + "|", + ("name", "=", order_ref), + ("partner_ref", "=", order_ref), + ("state", "in", ("purchase", "done")), + ], + limit=1, + ) + if not purchase_order: + return False + for invoice_line in invoice.invoice_line_ids: + self._match_invoice_line_to_purchase_order_line( + invoice_line, purchase_order.order_line + ) + return True + + def _match_invoice_line_to_purchase_order_line(self, invoice_line, purchase_lines): + """Match an invoice line to a purchase order line + + A match is considered when at least one of these conditions is true: + - same product + - same description + - invoice line description matches the purchase line product name + - supplier product code matches one of the vendor codes of the product + - invoice line description matches one of the vendor product names + """ + if invoice_line.purchase_line_id: + return False + + for purchase_line in purchase_lines: + product = purchase_line.product_id + seller_product_codes = product.seller_ids.mapped("product_code") + seller_product_names = product.seller_ids.mapped("product_name") + + same_product = product == invoice_line.product_id + same_description = purchase_line.name == invoice_line.name + matches_product_name = product.name == invoice_line.name + matches_supplier_code = ( + invoice_line.supplier_product_code in seller_product_codes + ) + matches_supplier_name = invoice_line.name in seller_product_names + + if any( + [ + same_product, + same_description, + matches_product_name, + matches_supplier_code, + matches_supplier_name, + ] + ): + invoice_line._set_product(product) + invoice_line.purchase_line_id = purchase_line + break + + return True + + def _import_fill_invoice_line_form( + self, journal, tree, invoice, invoice_line, qty_factor + ): + """ + add a fallback product lookup based on the supplier product code. + + the standard import logic doesn't cover this matching path, so if no product + was found after the super call, try to resolve it from supplierinfo using the + UBL SellerItemIdentification value + """ + res = super()._import_fill_invoice_line_form( + journal, tree, invoice, invoice_line, qty_factor + ) + if invoice_line.product_id: + return res + supplier_product_code = self._find_value( + "./cac:Item/cac:SellersItemIdentification/cbc:ID", tree + ) + if not supplier_product_code: + return res + invoice_line.supplier_product_code = supplier_product_code + product = self._retrieve_product_by_supplierinfo( + invoice.partner_id, supplier_product_code + ) + if not product: + return res + invoice_line._set_product(product) + return res + + def _retrieve_product_by_supplierinfo(self, partner, supplier_product_code): + """ + retrieve a product using supplierinfo based on: + - supplier (partner) + - supplier product code + + returns: + - product variant if directly linked + - single variant if template has only one variant + - empty recordset otherwise + """ + product_sinfo = self.env["product.supplierinfo"].search( + [ + ("product_code", "=", supplier_product_code), + ("partner_id", "=", partner.id), + ], + limit=1, + ) + if product_sinfo and product_sinfo.product_id: + return product_sinfo.product_id + if ( + product_sinfo + and product_sinfo.product_tmpl_id + and len(product_sinfo.product_tmpl_id.product_variant_ids) == 1 + ): + return product_sinfo.product_tmpl_id.product_variant_ids + return self.env["product.product"] diff --git a/account_edi_ubl_cii_purchase_match/models/account_move.py b/account_edi_ubl_cii_purchase_match/models/account_move.py new file mode 100644 index 0000000000..9bd222b5cc --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/account_move.py @@ -0,0 +1,57 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class AccountMove(models.Model): + + _inherit = "account.move" + + purchase_mismatch = fields.Boolean( + compute="_compute_purchase_mismatch", + help=( + "Checked when this invoice has at least one line that does not fully " + "match its related purchase order line." + ), + ) + purchase_mismatch_details = fields.Text( + compute="_compute_purchase_mismatch", + help=( + "Human-readable description of the differences between invoice lines " + "and their related purchase order lines." + ), + ) + + @api.depends( + "invoice_line_ids.purchase_line_mismatch", + "invoice_line_ids.purchase_line_mismatch_details", + "invoice_line_ids.product_id", + "invoice_line_ids.name", + ) + def _compute_purchase_mismatch(self): + for rec in self: + mismatch_lines = rec.invoice_line_ids.filtered("purchase_line_mismatch") + + if not mismatch_lines: + rec.purchase_mismatch = False + rec.purchase_mismatch_details = False + continue + + rec.purchase_mismatch = True + + purchase_mismatch_details = _( + "The following differences were detected between this invoice and its " + "related purchase order lines:\n" + ) + for line in mismatch_lines: + product_label = ( + line.product_id.display_name or line.name or _("No product") + ) + purchase_mismatch_details += product_label + "\n" + purchase_mismatch_details += line.purchase_line_mismatch_details + "\n" + rec.purchase_mismatch_details = purchase_mismatch_details + + def _link_invoice_origin_to_purchase_orders(self, timeout=10): + # disable standard purchase linking + return self diff --git a/account_edi_ubl_cii_purchase_match/models/account_move_line.py b/account_edi_ubl_cii_purchase_match/models/account_move_line.py new file mode 100644 index 0000000000..c917b0d2c8 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/account_move_line.py @@ -0,0 +1,147 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.tools import float_compare + + +class AccountMoveLine(models.Model): + + _inherit = "account.move.line" + supplier_product_code = fields.Char(readonly=True) + purchase_line_mismatch = fields.Boolean( + compute="_compute_purchase_line_mismatch", + help="Checked when this invoice line does not fully match its related purchase" + " order line.", + ) + purchase_line_mismatch_details = fields.Text( + compute="_compute_purchase_line_mismatch", + help="Human-readable description of the differences between this invoice line" + " and the related purchase order line.", + ) + + @api.depends( + "purchase_line_id", "move_id.state", "price_unit", "price_subtotal", "quantity" + ) + def _compute_purchase_line_mismatch(self): + for rec in self: + if not rec.purchase_line_id or rec.move_id.state != "draft": + rec.purchase_line_mismatch = False + rec.purchase_line_mismatch_details = False + continue + + differences = [] + po_line = rec.purchase_line_id + precision = rec.currency_id.rounding or 0.01 + if ( + float_compare( + rec.price_unit, + po_line.price_unit, + precision_rounding=precision, + ) + != 0 + ): + differences.append( + _("- Unit price differs from the purchase order line.") + ) + if ( + float_compare( + po_line.qty_invoiced, + po_line.product_uom_qty, + precision_rounding=po_line.product_uom.rounding or 0.01, + ) + > 0 + ): + differences.append( + _("- Invoiced quantity exceeds the ordered quantity.") + ) + if differences: + rec.purchase_line_mismatch = True + rec.purchase_line_mismatch_details = "\n".join(differences) + else: + rec.purchase_line_mismatch = False + rec.purchase_line_mismatch_details = False + + def _update_product_supplier_name(self): + for rec in self: + if not rec.name or not rec.product_id: + continue + seller = rec.product_id.seller_ids.filtered( + lambda s: s.partner_id == rec.move_id.partner_id + and ( + s.product_id == rec.product_id + or s.product_tmpl_id == rec.product_id.product_tmpl_id + ) + ) + if not seller: + rec.product_id.seller_ids.create( + { + "product_id": rec.product_id.id, + "product_code": rec.supplier_product_code, + "price": rec.price_unit, + } + ) + else: + if rec.supplier_product_code: + seller.product_code = rec.supplier_product_code + + def action_select_purchase_line(self): + self.ensure_one() + purchase_order = self.purchase_line_id.order_id + partner = self.move_id.partner_id + if not purchase_order and self.move_id.invoice_origin: + order_ref = self.move_id.invoice_origin + purchase_order = self.env["purchase.order"].search( + [ + "|", + ("name", "=", order_ref), + ("partner_ref", "=", order_ref), + ("state", "in", ("purchase", "done")), + ("partner_id", "=", partner.id), + ], + limit=1, + ) + context = { + **self.env.context, + **{ + "default_move_line_id": self.id, + "default_partner_id": partner.id, + "default_purchase_order_id": purchase_order.id, + "default_purchase_order_line_id": ( + self.purchase_line_id.id if purchase_order else False + ), + }, + } + return { + "type": "ir.actions.act_window", + "name": "Select Purchase Line", + "res_model": "account.move.line.select.purchase.line.wizard", + "view_mode": "form", + "target": "new", + "context": context, + } + + def action_show_purchase_line(self): + self.ensure_one() + if not self.purchase_line_id: + return {} + form = self.env.ref( + "account_edi_ubl_cii_purchase_match.purchase_order_line_form_view" + ) + return { + "type": "ir.actions.act_window", + "name": self.purchase_line_id.display_name, + "res_model": self.purchase_line_id._name, + "view_mode": "form", + "views": [(form.id, "form")], + "view_id": form.id, + "res_id": self.purchase_line_id.id, + "target": "new", + "context": self.env.context, + } + + def _set_product(self, product): + self.ensure_one() + price_unit = self.price_unit + self.product_id = product + self.price_unit = price_unit diff --git a/account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md b/account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md new file mode 100644 index 0000000000..dbefa8c9d6 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md @@ -0,0 +1,12 @@ +No configuration is required to use this module. + +However, for optimal matching: + +- Ensure that *OrderReference* in the vendor UBL document corresponds to the +Purchase Order Ref or the **Vendor Reference** (`partner_ref`). +- Maintain consistent **product names** or **supplier product names** so +that UBL line descriptions can be matched to the correct purchase order line. + +Optional but recommended: +- Define supplier product names (`product.supplierinfo`) to improve matching +accuracy. \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/readme/CONTEXT.md b/account_edi_ubl_cii_purchase_match/readme/CONTEXT.md new file mode 100644 index 0000000000..ad026776f5 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/CONTEXT.md @@ -0,0 +1,12 @@ +In the standard behavior, when importing a vendor bill from a UBL document: + +- If a Purchase Order is found, **all imported UBL lines are replaced** by +the Purchase Order lines. +- This causes a **loss of original UBL data**, such as: + - line-level descriptions, + - quantities, + - pricing, + - tax information received from the supplier. +- Additionally, the standard flow performs **no matching based on product labels**, +so incorrect PO lines may be added if PO content does not reflect what is +actually on the invoice. diff --git a/account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md b/account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..dbdd727b4a --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui diff --git a/account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md b/account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md new file mode 100644 index 0000000000..ae1764786e --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md @@ -0,0 +1,20 @@ +This module extends the UBL vendor bill import process to improve how vendor +bill lines are linked to purchase order lines. + +Instead of replacing the imported UBL lines with the purchase order lines +(standard behavior), this module: + +1. **Reads the OrderReference** in the UBL document. +2. **Identifies the corresponding Purchase Order** using the vendor reference +(`partner_ref`) or the purchase order ref. +3. **Matches each UBL line** with a purchase order line based on: + - product name, + - supplier product name + +4. **Links the vendor bill line** to the matched PO line +5. When a user manually selects a purchase order line from the bill: + - the system stores the supplier product name, + - future imports will auto-match using that supplier information. + +This ensures accurate line-level linking while preserving the supplier’s +invoice data. \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/readme/ROADMAP.md b/account_edi_ubl_cii_purchase_match/readme/ROADMAP.md new file mode 100644 index 0000000000..b5071ac30d --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/ROADMAP.md @@ -0,0 +1,10 @@ +This module implements custom purchase order line matching and replaces +the standard behavior of linking vendor bills to purchase orders via UBL. + +Before migrating to future versions, it is recommended to verify whether: +- Odoo natively supports precise line-level matching, +- supplier product names and UBL descriptions are matched out of the box, +- and the original UBL lines are preserved. + +If the standard behavior evolves to fully cover this business requirement, +this module may become unnecessary. diff --git a/account_edi_ubl_cii_purchase_match/readme/USAGE.md b/account_edi_ubl_cii_purchase_match/readme/USAGE.md new file mode 100644 index 0000000000..fb514c3940 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/USAGE.md @@ -0,0 +1,11 @@ +1. Import a vendor bill in UBL format through: Accounting / Vendors / Bills / Upload +2. The module will automatically: + - Extract the OrderReference from the UBL. + - Find the matching purchase order via `partner_ref` or purchase order ref. + - Attempt to match each UBL line with the correct purchase order line using: + - product name, + - supplier product name +3. When a match is found: the vendor bill line is linked to the purchase order line. +4. If no match is found: + - Click "Select purchase line" button in invoice line + - Select a purchase order and a purchase order line \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml b/account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml new file mode 100644 index 0000000000..b55260f160 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml @@ -0,0 +1,24 @@ + + + + + + account.move.line.select.purchase.line.wizard access all + + + + + + + + + diff --git a/account_edi_ubl_cii_purchase_match/static/description/icon.png b/account_edi_ubl_cii_purchase_match/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=FhLB@(1&qHA5EJw1>>=%q2f&^X>IQ{!GJ4e9U z&KlB)z(84HmNgm2hg2C0>WM{E(DdPr+EeU_N@57;PC2&DmGFW_9kP&%?X4}+xWi)( z;)z%wI5>D4a*5XwD)P--sPkoY(a~WBw;E~AW`Yue4kFa^LM3X`8x|}ZUeMnqr}>kH zG%WWW>3ml$Yez?i%)2pbKPI7?5o?hydokgQyZsNEr{a|mLdt;X2TX(#B1j35xPnPW z*bMSSOauW>o;*=kO8ojw91VX!qoOQb)zHJ!odWB}d+*K?#sY_jqPdg{Sm2HdYzdEx zOGVPhVRTGPtv0o}RfVP;Nd(|CB)I;*t&QO8h zFfekr30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iomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/account_edi_ubl_cii_purchase_match/static/description/index.html b/account_edi_ubl_cii_purchase_match/static/description/index.html new file mode 100644 index 0000000000..035f9e5bf0 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/static/description/index.html @@ -0,0 +1,526 @@ + + + + + +Account Edi Ubl Cii Purchase Match + + + +
+

Account Edi Ubl Cii Purchase Match

+ + +

Beta License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runboat

+

This module extends the UBL vendor bill import process to improve how +vendor bill lines are linked to purchase order lines.

+

Instead of replacing the imported UBL lines with the purchase order +lines (standard behavior), this module:

+
    +
  1. Reads the OrderReference in the UBL document.
  2. +
  3. Identifies the corresponding Purchase Order using the vendor +reference (partner_ref) or the purchase order ref.
  4. +
  5. Matches each UBL line with a purchase order line based on:
      +
    • product name,
    • +
    • supplier product name
    • +
    +
  6. +
  7. Links the vendor bill line to the matched PO line
  8. +
  9. When a user manually selects a purchase order line from the bill:
      +
    • the system stores the supplier product name,
    • +
    • future imports will auto-match using that supplier information.
    • +
    +
  10. +
+

This ensures accurate line-level linking while preserving the supplier’s +invoice data.

+

Table of contents

+ +
+

Use Cases / Context

+

In the standard behavior, when importing a vendor bill from a UBL +document:

+
    +
  • If a Purchase Order is found, all imported UBL lines are replaced +by the Purchase Order lines.
  • +
  • This causes a loss of original UBL data, such as:
      +
    • line-level descriptions,
    • +
    • quantities,
    • +
    • pricing,
    • +
    • tax information received from the supplier.
    • +
    +
  • +
  • Additionally, the standard flow performs no matching based on +product labels, so incorrect PO lines may be added if PO content +does not reflect what is actually on the invoice.
  • +
+
+
+

Configuration

+

No configuration is required to use this module.

+

However, for optimal matching:

+
    +
  • Ensure that OrderReference in the vendor UBL document corresponds to +the Purchase Order Ref or the Vendor Reference (partner_ref).
  • +
  • Maintain consistent product names or supplier product names so +that UBL line descriptions can be matched to the correct purchase +order line.
  • +
+

Optional but recommended:

+
    +
  • Define supplier product names (product.supplierinfo) to improve +matching accuracy.
  • +
+
+
+

Usage

+
    +
  1. Import a vendor bill in UBL format through: Accounting / Vendors / +Bills / Upload
  2. +
  3. The module will automatically:
      +
    • Extract the OrderReference from the UBL.
    • +
    • Find the matching purchase order via partner_ref or purchase +order ref.
    • +
    • Attempt to match each UBL line with the correct purchase order line +using:
        +
      • product name,
      • +
      • supplier product name
      • +
      +
    • +
    +
  4. +
  5. When a match is found: the vendor bill line is linked to the purchase +order line.
  6. +
  7. If no match is found:
      +
    • Click “Select purchase line” button in invoice line
    • +
    • Select a purchase order and a purchase order line
    • +
    +
  8. +
+
+
+

Known issues / Roadmap

+

This module implements custom purchase order line matching and replaces +the standard behavior of linking vendor bills to purchase orders via +UBL.

+

Before migrating to future versions, it is recommended to verify +whether:

+
    +
  • Odoo natively supports precise line-level matching,
  • +
  • supplier product names and UBL descriptions are matched out of the +box,
  • +
  • and the original UBL lines are preserved.
  • +
+

If the standard behavior evolves to fully cover this business +requirement, this module may become unnecessary.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/edi project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_edi_ubl_cii_purchase_match/tests/__init__.py b/account_edi_ubl_cii_purchase_match/tests/__init__.py new file mode 100644 index 0000000000..df41f3af05 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_edi_ubl_cii_purchase_match diff --git a/account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py b/account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py new file mode 100644 index 0000000000..73b32749d7 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py @@ -0,0 +1,292 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command +from odoo.tests import tagged +from odoo.tools import file_open + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountEdiUblCiiPurchaseMatch(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass() + cls.product = cls.env["product.product"].create( + {"name": "test_product", "standard_price": 100} + ) + cls.partner = cls.env["res.partner"].create( + {"name": "ALD Automotive LU", "vat": "LU25587702"} + ) + cls.purchase_order = cls.env["purchase.order"].create( + { + "partner_id": cls.partner.id, + "order_line": [ + Command.create( + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_qty": 1, + "price_unit": 657, + } + ), + ], + } + ) + cls.po_line = cls.purchase_order.order_line + cls.purchase_order.button_confirm() + + def _import_invoice(self, journal, file_path=None): + if file_path is None: + file_path = ( + "account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example.xml" + ) + with file_open(file_path, "rb") as file: + xml_attachment = self.env["ir.attachment"].create( + { + "mimetype": "application/xml", + "name": "test_invoice.xml", + "raw": file.read(), + } + ) + move = ( + self.env["account.journal"] + .with_context(default_journal_id=journal.id) + ._create_document_from_attachment(xml_attachment.id) + ) + return move + + def test_0(self): + """ + Default behavior + without matching criteria, no purchase line or product + is assigned. Sale journals are also ignored + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + self.assertEqual(bill.partner_id, self.partner) + inv_line = bill.invoice_line_ids + self.assertFalse(inv_line.purchase_line_id) + self.assertFalse(inv_line.product_id) + invoice = self._import_invoice(self.company_data["default_journal_sale"]) + self.assertEqual(invoice.partner_id, self.partner) + inv_line = invoice.invoice_line_ids + self.assertFalse(inv_line.purchase_line_id) + self.assertFalse(inv_line.product_id) + + def test_1(self): + """ + OrderReference matches a purchase order, but no product match is found. + Standard behavior is disabled: no PO lines are created from the PO, only the + UBL invoice line is imported + """ + self.purchase_order.partner_ref = "FAC/2023/00052" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(len(inv_line), 1) # standard behavior is desabled + self.assertFalse(inv_line.purchase_line_id) + self.assertFalse(inv_line.product_id) + + def test_2(self): + """ + The product name matches the UBL line description, so the vendor bill line is + linked to the PO line and the product is set accordingly + """ + self.purchase_order.partner_ref = "FAC/2023/00052" + self.product.name = "Locations and leasing" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + return inv_line + + def test_3(self): + """ + The supplier product name (defined on the product variant via supplierinfo) + matches the UBL line description, so the bill line is correctly linked to the + PO line and product + """ + + self.purchase_order.partner_ref = "FAC/2023/00052" + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_name": "Locations and leasing", + "product_id": self.product.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_4(self): + """ + The supplier product name (defined on the product template via supplierinfo) + matches the UBL line description, so the bill line is linked to the PO line and + product + """ + + self.purchase_order.partner_ref = "FAC/2023/00052" + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_name": "Locations and leasing", + "product_tmpl_id": self.product.product_tmpl_id.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_5(self): + """ + When no product match is found, the user manually links the bill line to the PO + line, the supplier info is updated with the product supplier name + On the next import, the supplierinfo is used to automatically match the + bill line with the correct PO line + """ + self.purchase_order.partner_ref = "FAC/2023/00052" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertFalse(inv_line.purchase_line_id) + self.assertEqual(inv_line.price_unit, 657.0) + action = inv_line.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + self.assertEqual(wizard.move_line_id, inv_line) + self.assertEqual(wizard.purchase_order_id, self.purchase_order) + wizard.product_id = self.product + wizard.select_purchase_line() + self.assertEqual(inv_line.purchase_line_id, self.po_line) + bill.unlink() + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + + def test_6(self): + """ + price unit imported from file is unchanged after po auto match + """ + inv_line = self.test_2() + self.assertEqual(inv_line.price_unit, 657.0) + inv_line.product_id = False + inv_line.product_id = self.product + self.assertEqual(inv_line.price_unit, 100) + + def test_7(self): + """ + price unit imported from file is unchanged after po manual match + """ + self.purchase_order.partner_ref = "FAC/2023/00052" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.price_unit, 657.0) + action = inv_line.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + wizard.product_id = self.product + wizard.select_purchase_line() + self.assertEqual(inv_line.price_unit, 657.0) + + def test_8(self): + """match product by default_code""" + self.purchase_order.partner_ref = "FAC/2023/00052" + self.product.default_code = "leasing001" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_9(self): + """match product by supplier code""" + self.purchase_order.partner_ref = "FAC/2023/00052" + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_code": "leasing001", + "product_id": self.product.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_10(self): + """match product by supplier code for product template suuplierinfo""" + self.purchase_order.partner_ref = "FAC/2023/00052" + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_code": "leasing001", + "product_tmpl_id": self.product.product_tmpl_id.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_11(self): + """ + product supplier code is stored in seller information at manual match + """ + self.purchase_order.partner_ref = "FAC/2023/00052" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.supplier_product_code, "leasing001") + self.assertEqual(inv_line.price_unit, 657.0) + action = inv_line.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + wizard.product_id = self.product + wizard.select_purchase_line() + self.assertEqual(self.product.seller_ids.product_code, "leasing001") + + def test_12(self): + """test purchase price unit mismatch warning""" + self.purchase_order.partner_ref = "FAC/2023/00052" + self.product.default_code = "leasing001" + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + file_path="account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example_price_unit_mismatch.xml", + ) + self.assertTrue(bill.purchase_mismatch) + self.assertIn( + "Unit price differs from the purchase order line", + bill.purchase_mismatch_details, + ) + bill.action_post() + self.assertFalse(bill.purchase_mismatch) + self.assertFalse(bill.purchase_mismatch_details) + + def test_13(self): + """test purchase invoiced qty mismatch warning""" + self.purchase_order.partner_ref = "FAC/2023/00052" + self.product.default_code = "leasing001" + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + file_path="account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example_invoiced_qty_mismatch.xml", + ) + self.assertTrue(bill.purchase_mismatch) + self.assertIn( + "Invoiced quantity exceeds the ordered quantity", + bill.purchase_mismatch_details, + ) + bill.action_post() + self.assertFalse(bill.purchase_mismatch) + self.assertFalse(bill.purchase_mismatch_details) diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml new file mode 100644 index 0000000000..03a910f158 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml @@ -0,0 +1,144 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 105.12 + + 657.00 + 105.12 + + S + 16.0 + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + S + 16.0 + + VAT + + + + + 657.00 + + + diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml new file mode 100644 index 0000000000..940c366a17 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml @@ -0,0 +1,144 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 160 + + 1000 + 160 + + S + 16.0 + + VAT + + + + + + 1000 + 1000 + 1160 + 0.00 + 1160 + + + 1 + 10.0 + 1000 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + S + 16.0 + + VAT + + + + + 1000 + + + diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml new file mode 100644 index 0000000000..8b50e525db --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml @@ -0,0 +1,144 @@ + + + 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 + FAC/2023/00052 + 2023-08-04 + 2023-09-04 + 380 + EUR + + FAC/2023/00052 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + FAC/2023/00052 + + LU071241358706500000 + + + + 160 + + 1000 + 160 + + S + 16.0 + + VAT + + + + + + 1000 + 1000 + 1160 + 0.00 + 1160 + + + 1 + 1.0 + 1000 + + Locations and leasing + Locations et leasing opérationnel + + leasing001 + + + S + 16.0 + + VAT + + + + + 1000 + + + diff --git a/account_edi_ubl_cii_purchase_match/views/account_move.xml b/account_edi_ubl_cii_purchase_match/views/account_move.xml new file mode 100644 index 0000000000..2ae7a31cf9 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/views/account_move.xml @@ -0,0 +1,51 @@ + + + + + + account.move + + + + + + +