diff --git a/account_edi_no_autocreate_partner/README.rst b/account_edi_no_autocreate_partner/README.rst new file mode 100644 index 0000000000..bc49246039 --- /dev/null +++ b/account_edi_no_autocreate_partner/README.rst @@ -0,0 +1,88 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================================= +Account Edi No Autocreate Partner +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7c5949ecd88b3f1f91c8c5a259191718774c342664a36ba6de7ae4d6189916e4 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/account_edi_no_autocreate_partner + :alt: OCA/edi +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/edi-19-0/edi-19-0-account_edi_no_autocreate_partner + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module modifies the invoice import process so that no longer +partners are auto-created when no matching is found. + +Instead, imported invoices that cannot be linked to an existing partner +are automatically assigned to a dedicated fallback partner named +"Partner Not Found". + +This prevents uncontrolled partner creation and allows users to manually +review and correct partner information before posting invoices. + +**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 + +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_no_autocreate_partner/__init__.py b/account_edi_no_autocreate_partner/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/account_edi_no_autocreate_partner/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_edi_no_autocreate_partner/__manifest__.py b/account_edi_no_autocreate_partner/__manifest__.py new file mode 100644 index 0000000000..561ab55bd1 --- /dev/null +++ b/account_edi_no_autocreate_partner/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Edi No Autocreate Partner", + "summary": """Prevents auto-creation of partners during invoice import by + assigning unmatched invoices to a protected “Partner Not Found” contact.""", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/edi", + "depends": ["account_edi"], + "data": ["data/res_partner.xml"], + "demo": [], +} diff --git a/account_edi_no_autocreate_partner/data/res_partner.xml b/account_edi_no_autocreate_partner/data/res_partner.xml new file mode 100644 index 0000000000..4b5c67557c --- /dev/null +++ b/account_edi_no_autocreate_partner/data/res_partner.xml @@ -0,0 +1,12 @@ + + + + + Partner Not Found + + + Fallback partner used when a vendor cannot be matched during UBL import. + + + diff --git a/account_edi_no_autocreate_partner/i18n/account_edi_no_autocreate_partner.pot b/account_edi_no_autocreate_partner/i18n/account_edi_no_autocreate_partner.pot new file mode 100644 index 0000000000..3abf6f8d87 --- /dev/null +++ b/account_edi_no_autocreate_partner/i18n/account_edi_no_autocreate_partner.pot @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_edi_no_autocreate_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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_no_autocreate_partner +#: model:ir.model,name:account_edi_no_autocreate_partner.model_res_partner +msgid "Contact" +msgstr "" + +#. module: account_edi_no_autocreate_partner +#: model:ir.model,name:account_edi_no_autocreate_partner.model_account_edi_format +msgid "EDI format" +msgstr "" + +#. module: account_edi_no_autocreate_partner +#: model:ir.model,name:account_edi_no_autocreate_partner.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_edi_no_autocreate_partner +#. odoo-python +#: code:addons/account_edi_no_autocreate_partner/models/res_partner.py:0 +#, python-format +msgid "" +"You cannot activate the fallback 'Partner Not Found' contact used for " +"invoice imports." +msgstr "" + +#. module: account_edi_no_autocreate_partner +#. odoo-python +#: code:addons/account_edi_no_autocreate_partner/models/res_partner.py:0 +#, python-format +msgid "" +"You cannot delete the fallback 'Partner Not Found' contact used for invoice " +"imports." +msgstr "" + +#. module: account_edi_no_autocreate_partner +#. odoo-python +#: code:addons/account_edi_no_autocreate_partner/models/account_move.py:0 +#, python-format +msgid "" +"You must assign a proper vendor before posting this invoice. The fallback " +"'Partner Not Found' partner cannot be used on posted moves." +msgstr "" diff --git a/account_edi_no_autocreate_partner/i18n/it.po b/account_edi_no_autocreate_partner/i18n/it.po new file mode 100644 index 0000000000..28f1e14479 --- /dev/null +++ b/account_edi_no_autocreate_partner/i18n/it.po @@ -0,0 +1,66 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_edi_no_autocreate_partner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-01-05 20:43+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: account_edi_no_autocreate_partner +#: model:ir.model,name:account_edi_no_autocreate_partner.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: account_edi_no_autocreate_partner +#: model:ir.model,name:account_edi_no_autocreate_partner.model_account_edi_format +msgid "EDI format" +msgstr "Formato EDI" + +#. module: account_edi_no_autocreate_partner +#: model:ir.model,name:account_edi_no_autocreate_partner.model_account_move +msgid "Journal Entry" +msgstr "Registrazione contabile" + +#. module: account_edi_no_autocreate_partner +#. odoo-python +#: code:addons/account_edi_no_autocreate_partner/models/res_partner.py:0 +#, python-format +msgid "" +"You cannot activate the fallback 'Partner Not Found' contact used for " +"invoice imports." +msgstr "" +"Non è possibile attivare il contatto alternativo \"Partner non trovato\" " +"utilizzato per l'importazione delle fatture." + +#. module: account_edi_no_autocreate_partner +#. odoo-python +#: code:addons/account_edi_no_autocreate_partner/models/res_partner.py:0 +#, python-format +msgid "" +"You cannot delete the fallback 'Partner Not Found' contact used for invoice " +"imports." +msgstr "" +"Non è possibile attivare il contatto alternativo \"Partner non trovato\" " +"utilizzato per l'importazione delle fatture." + +#. module: account_edi_no_autocreate_partner +#. odoo-python +#: code:addons/account_edi_no_autocreate_partner/models/account_move.py:0 +#, python-format +msgid "" +"You must assign a proper vendor before posting this invoice. The fallback " +"'Partner Not Found' partner cannot be used on posted moves." +msgstr "" +"È necessario assegnare un fornitore corretto prima di registrare questa " +"fattura. Il partner alternativo \"Partner non trovato\" non può essere " +"utilizzato per i movimenti registrati." diff --git a/account_edi_no_autocreate_partner/models/__init__.py b/account_edi_no_autocreate_partner/models/__init__.py new file mode 100644 index 0000000000..45c17a4cc3 --- /dev/null +++ b/account_edi_no_autocreate_partner/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner +from . import account_move diff --git a/account_edi_no_autocreate_partner/models/account_move.py b/account_edi_no_autocreate_partner/models/account_move.py new file mode 100644 index 0000000000..a31858a334 --- /dev/null +++ b/account_edi_no_autocreate_partner/models/account_move.py @@ -0,0 +1,24 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.exceptions import UserError + + +class AccountMove(models.Model): + _inherit = "account.move" + + def action_post(self): + partner_not_found = self.env.ref( + "account_edi_no_autocreate_partner.partner_not_found" + ) + for move in self: + if move.partner_id == partner_not_found: + raise UserError( + self.env._( + "You must assign a proper vendor before posting this invoice. " + "The fallback 'Partner Not Found' partner cannot be used on " + "posted moves." + ) + ) + return super().action_post() diff --git a/account_edi_no_autocreate_partner/models/res_partner.py b/account_edi_no_autocreate_partner/models/res_partner.py new file mode 100644 index 0000000000..663a75775d --- /dev/null +++ b/account_edi_no_autocreate_partner/models/res_partner.py @@ -0,0 +1,49 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models +from odoo.exceptions import UserError + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.ondelete(at_uninstall=False) + def _prevent_no_autocreate_partner_unlink(self): + partner_not_found = self.env.ref( + "account_edi_no_autocreate_partner.partner_not_found" + ) + if partner_not_found in self: + raise UserError( + self.env._( + "You cannot delete the fallback 'Partner Not Found' contact " + "used for invoice imports." + ) + ) + return super().unlink() + + def write(self, vals): + if "active" in vals and vals["active"]: + partner_not_found = self.env.ref( + "account_edi_no_autocreate_partner.partner_not_found" + ) + if partner_not_found in self: + raise UserError( + self.env._( + "You cannot activate the fallback 'Partner Not Found' " + "contact used for invoice imports." + ) + ) + return super().write(vals) + + def _retrieve_partner( + self, name=None, phone=None, email=None, vat=None, domain=None, company=None + ): + partner = super()._retrieve_partner( + name=name, phone=phone, email=email, vat=vat, domain=domain, company=company + ) + if not partner: + partner = self.env.ref( + "account_edi_no_autocreate_partner.partner_not_found" + ) + return partner diff --git a/account_edi_no_autocreate_partner/pyproject.toml b/account_edi_no_autocreate_partner/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/account_edi_no_autocreate_partner/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_edi_no_autocreate_partner/readme/CONTRIBUTORS.md b/account_edi_no_autocreate_partner/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..dbdd727b4a --- /dev/null +++ b/account_edi_no_autocreate_partner/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui diff --git a/account_edi_no_autocreate_partner/readme/DESCRIPTION.md b/account_edi_no_autocreate_partner/readme/DESCRIPTION.md new file mode 100644 index 0000000000..fd56f714af --- /dev/null +++ b/account_edi_no_autocreate_partner/readme/DESCRIPTION.md @@ -0,0 +1,9 @@ +This module modifies the invoice import process so that no longer partners are +auto-created when no matching is found. + +Instead, imported invoices that cannot be linked to an existing partner +are automatically assigned to a dedicated fallback partner named +"Partner Not Found". + +This prevents uncontrolled partner creation and allows users to manually +review and correct partner information before posting invoices. diff --git a/account_edi_no_autocreate_partner/static/description/icon.png b/account_edi_no_autocreate_partner/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/account_edi_no_autocreate_partner/static/description/icon.png differ diff --git a/account_edi_no_autocreate_partner/static/description/index.html b/account_edi_no_autocreate_partner/static/description/index.html new file mode 100644 index 0000000000..8a837e9a6f --- /dev/null +++ b/account_edi_no_autocreate_partner/static/description/index.html @@ -0,0 +1,435 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Account Edi No Autocreate Partner

+ +

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

+

This module modifies the invoice import process so that no longer +partners are auto-created when no matching is found.

+

Instead, imported invoices that cannot be linked to an existing partner +are automatically assigned to a dedicated fallback partner named +“Partner Not Found”.

+

This prevents uncontrolled partner creation and allows users to manually +review and correct partner information before posting invoices.

+

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
  • +
+
+
+

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_no_autocreate_partner/tests/__init__.py b/account_edi_no_autocreate_partner/tests/__init__.py new file mode 100644 index 0000000000..8ec5aab01e --- /dev/null +++ b/account_edi_no_autocreate_partner/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_edi_no_autocreate_partner diff --git a/account_edi_no_autocreate_partner/tests/test_account_edi_no_autocreate_partner.py b/account_edi_no_autocreate_partner/tests/test_account_edi_no_autocreate_partner.py new file mode 100644 index 0000000000..d4419ab4f2 --- /dev/null +++ b/account_edi_no_autocreate_partner/tests/test_account_edi_no_autocreate_partner.py @@ -0,0 +1,75 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import UserError +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 TestAccountEdiNoAutocreatePartner(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass() + cls.partner_not_found = cls.env.ref( + "account_edi_no_autocreate_partner.partner_not_found" + ) + cls.env.ref("base.EUR").active = True + + def _import_invoice(self, journal): + file_path = ( + "account_edi_no_autocreate_partner/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 _is_partner_exists(self): + return bool(self.env["res.partner"].search([("vat", "=", "LU12977109")])) + + def test_1(self): + """check partner is not created if not existing""" + + self.assertFalse(self._is_partner_exists()) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + self.assertFalse(self._is_partner_exists()) + self.assertEqual(bill.partner_id, self.partner_not_found) + return bill + + def test_2(self): + """check partner_not_found can't be activated""" + with self.assertRaisesRegex( + UserError, "You cannot activate the fallback 'Partner Not Found'" + ): + self.partner_not_found.active = True + + def test_3(self): + """check partner_not_found can't be deleted""" + with self.assertRaisesRegex( + UserError, "You cannot delete the fallback 'Partner Not Found'" + ): + self.partner_not_found.unlink() + + def test_4(self): + """check invoices linked to partner_not_found can't be posted""" + bill = self.test_1() + with self.assertRaisesRegex( + UserError, "You must assign a proper vendor before posting this invoice" + ): + bill.action_post() + bill.partner_id = self.partner_a + bill.action_post() + self.assertEqual(bill.state, "posted") diff --git a/account_edi_no_autocreate_partner/tests/test_files/bis3_bill_example.xml b/account_edi_no_autocreate_partner/tests/test_files/bis3_bill_example.xml new file mode 100644 index 0000000000..088cf7c93f --- /dev/null +++ b/account_edi_no_autocreate_partner/tests/test_files/bis3_bill_example.xml @@ -0,0 +1,145 @@ + + + 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 + + + Sales Department + 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 + + + + + + partner_a + + + + + 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 + + product_a + product_a + + S + 16.0 + + VAT + + + + + 657.00 + + +