diff --git a/account_payment_order_lock_draft/README.rst b/account_payment_order_lock_draft/README.rst new file mode 100644 index 000000000..438c06931 --- /dev/null +++ b/account_payment_order_lock_draft/README.rst @@ -0,0 +1,90 @@ +================================ +Account Payment Order Lock Draft +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3f92f29d95bdee2b4c64e55895ba86f2e130dc9657dbdd0c0ae637acb52f575f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fbank--payment-lightgray.png?logo=github + :target: https://github.com/OCA/bank-payment/tree/14.0/account_payment_order_lock_draft + :alt: OCA/bank-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_order_lock_draft + :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/bank-payment&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds functionality that prevents invoices from being reset to the draft status if they are linked to a Payment Order that is in progress. + +**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 +~~~~~~~ + +* Escodoo + +Contributors +~~~~~~~~~~~~ + +* `Escodoo `_: + + * Marcel Savegnago + * Kaynnan Lemes + +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-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px + :target: https://github.com/marcelsavegnago + :alt: marcelsavegnago +.. |maintainer-kaynnan| image:: https://github.com/kaynnan.png?size=40px + :target: https://github.com/kaynnan + :alt: kaynnan + +Current `maintainers `__: + +|maintainer-marcelsavegnago| |maintainer-kaynnan| + +This module is part of the `OCA/bank-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_order_lock_draft/__init__.py b/account_payment_order_lock_draft/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_payment_order_lock_draft/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_order_lock_draft/__manifest__.py b/account_payment_order_lock_draft/__manifest__.py new file mode 100644 index 000000000..5d69c0500 --- /dev/null +++ b/account_payment_order_lock_draft/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2024 - TODAY, Escodoo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Payment Order Lock Draft", + "summary": """ + Account Payment Order Lock Draft""", + "version": "14.0.1.0.0", + "license": "AGPL-3", + "author": "Escodoo,Odoo Community Association (OCA)", + "maintainers": ["marcelsavegnago", "kaynnan"], + "website": "https://github.com/OCA/bank-payment", + "depends": ["account_payment_order"], +} diff --git a/account_payment_order_lock_draft/models/__init__.py b/account_payment_order_lock_draft/models/__init__.py new file mode 100644 index 000000000..9c0a42138 --- /dev/null +++ b/account_payment_order_lock_draft/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/account_payment_order_lock_draft/models/account_move.py b/account_payment_order_lock_draft/models/account_move.py new file mode 100644 index 000000000..fa118fd92 --- /dev/null +++ b/account_payment_order_lock_draft/models/account_move.py @@ -0,0 +1,34 @@ +# Copyright 2024 - TODAY, Kaynnan Lemes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +# flake8: noqa: B950 + +from odoo import _, models +from odoo.exceptions import UserError + + +class AccountMove(models.Model): + + _inherit = "account.move" + + def button_draft(self): + """Handles the action of resetting entries to draft status. + + Performs the operation of resetting entries to draft status. It iterates + through each entry, verifies if any associated payment order, and raises a UserError if so, preventing the reset operation. + + Raises: + UserError: If an entry is associated with a Payment Order + """ + super().button_draft() + for move in self: + if ( + self.env["account.move"] + .sudo() + .browse(move.id) + .line_ids.filtered(lambda line: line.payment_line_ids) + ): + raise UserError( + _( + "You can't reset to draft because it's already associated with a Payment Order." + ) + ) diff --git a/account_payment_order_lock_draft/readme/CONTRIBUTORS.rst b/account_payment_order_lock_draft/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..c7fe69086 --- /dev/null +++ b/account_payment_order_lock_draft/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Escodoo `_: + + * Marcel Savegnago + * Kaynnan Lemes diff --git a/account_payment_order_lock_draft/readme/DESCRIPTION.rst b/account_payment_order_lock_draft/readme/DESCRIPTION.rst new file mode 100644 index 000000000..49abb9331 --- /dev/null +++ b/account_payment_order_lock_draft/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds functionality that prevents invoices from being reset to the draft status if they are linked to a Payment Order that is in progress. diff --git a/account_payment_order_lock_draft/static/description/icon.png b/account_payment_order_lock_draft/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_payment_order_lock_draft/static/description/icon.png differ diff --git a/account_payment_order_lock_draft/static/description/index.html b/account_payment_order_lock_draft/static/description/index.html new file mode 100644 index 000000000..b51372ef9 --- /dev/null +++ b/account_payment_order_lock_draft/static/description/index.html @@ -0,0 +1,426 @@ + + + + + +Account Payment Order Lock Draft + + + +
+

Account Payment Order Lock Draft

+ + +

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

+

This module adds functionality that prevents invoices from being reset to the draft status if they are linked to a Payment Order that is in progress.

+

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

+
    +
  • Escodoo
  • +
+
+
+

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:

+

marcelsavegnago kaynnan

+

This module is part of the OCA/bank-payment project on GitHub.

+

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

+
+
+
+ + diff --git a/account_payment_order_lock_draft/tests/__init__.py b/account_payment_order_lock_draft/tests/__init__.py new file mode 100644 index 000000000..46267cfc6 --- /dev/null +++ b/account_payment_order_lock_draft/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_payment_order_lock_draft diff --git a/account_payment_order_lock_draft/tests/test_account_payment_order_lock_draft.py b/account_payment_order_lock_draft/tests/test_account_payment_order_lock_draft.py new file mode 100644 index 000000000..a0ff7b6f4 --- /dev/null +++ b/account_payment_order_lock_draft/tests/test_account_payment_order_lock_draft.py @@ -0,0 +1,62 @@ +# Copyright 2024 - TODAY, Kaynnan Lemes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date + +from odoo.exceptions import UserError +from odoo.tests import common, tagged + + +@tagged("-at_install", "post_install") +class TestAccountPaymentOrderLockDraft(common.SavepointCase): + @classmethod + def setUpClass(cls): + """ + Set up necessary data for the test class. + """ + super().setUpClass() + # Date + cls.date = date.today() + # Product + cls.product = cls.env.ref("product.product_product_7") + # Partner + cls.partner = cls.env.ref("base.res_partner_2") + # Partner Bank + cls.partner_bank = cls.env.ref("account_payment_mode.main_company_iban") + # Payment Mode + cls.payment_mode = cls.env.ref("account_payment_mode.payment_mode_outbound_ct1") + # Invoice + cls.invoice = cls.env["account.move"].create( + { + "partner_id": cls.partner.id, + "invoice_date": cls.date, + "move_type": "out_invoice", + "payment_mode_id": cls.payment_mode.id, + "partner_bank_id": cls.partner_bank.id, + "invoice_line_ids": [ + ( + 0, + 0, + { + "product_id": cls.product.id, + "price_unit": 50.0, + "quantity": 1, + }, + ) + ], + } + ) + + def test_invoice_restriction(self): + """ + Test if UserError is raised when trying to revert an invoice to draft + status while it's associated with a Payment Order. + """ + invoice = self.invoice + # Confirm Invoice + invoice.action_post() + # Create Account Payment Line + invoice.create_account_payment_line() + # Check Invoice associated with a Payment Order + with self.assertRaises(UserError): + invoice.button_draft() diff --git a/setup/account_payment_order_lock_draft/odoo/addons/account_payment_order_lock_draft b/setup/account_payment_order_lock_draft/odoo/addons/account_payment_order_lock_draft new file mode 120000 index 000000000..78a29c0a7 --- /dev/null +++ b/setup/account_payment_order_lock_draft/odoo/addons/account_payment_order_lock_draft @@ -0,0 +1 @@ +../../../../account_payment_order_lock_draft \ No newline at end of file diff --git a/setup/account_payment_order_lock_draft/setup.py b/setup/account_payment_order_lock_draft/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_payment_order_lock_draft/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)