diff --git a/account_move_reconcile_forbid_cancel/README.rst b/account_move_reconcile_forbid_cancel/README.rst new file mode 100644 index 00000000..07fd02aa --- /dev/null +++ b/account_move_reconcile_forbid_cancel/README.rst @@ -0,0 +1,88 @@ +==================================== +Account Move Reconcile Forbid Cancel +==================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--reconcile-lightgray.png?logo=github + :target: https://github.com/OCA/account-reconcile/tree/15.0/account_move_reconcile_forbid_cancel + :alt: OCA/account-reconcile +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-reconcile-15-0/account-reconcile-15-0-account_move_reconcile_forbid_cancel + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/98/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module restricts to cancel or reset to draft any invoice/journal entry that +has been reconciled (aka paid). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to *Invoicing > Customers > Invoices* +#. Access an invoice that has a payment. +#. Click on the 'Reset to Draft' button and you will get an error + message to prevent you from resetting the invoice to draft state because + it has already an associated payment. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + +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/account-reconcile `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_reconcile_forbid_cancel/__init__.py b/account_move_reconcile_forbid_cancel/__init__.py new file mode 100644 index 00000000..31660d6a --- /dev/null +++ b/account_move_reconcile_forbid_cancel/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_move_reconcile_forbid_cancel/__manifest__.py b/account_move_reconcile_forbid_cancel/__manifest__.py new file mode 100644 index 00000000..65553875 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/__manifest__.py @@ -0,0 +1,12 @@ +# Copyright 2022 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Move Reconcile Forbid Cancel", + "version": "16.0.1.0.0", + "category": "Finance", + "website": "https://github.com/OCA/account-reconcile", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["account"], +} diff --git a/account_move_reconcile_forbid_cancel/i18n/account_move_reconcile_forbid_cancel.pot b/account_move_reconcile_forbid_cancel/i18n/account_move_reconcile_forbid_cancel.pot new file mode 100644 index 00000000..118bb419 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/i18n/account_move_reconcile_forbid_cancel.pot @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_reconcile_forbid_cancel +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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_move_reconcile_forbid_cancel +#: model:ir.model,name:account_move_reconcile_forbid_cancel.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_move_reconcile_forbid_cancel +#: code:addons/account_move_reconcile_forbid_cancel/models/account_move.py:0 +#, python-format +msgid "You cannot cancel reconciled entries." +msgstr "" + +#. module: account_move_reconcile_forbid_cancel +#: code:addons/account_move_reconcile_forbid_cancel/models/account_move.py:0 +#, python-format +msgid "You cannot reset to draft reconciled entries." +msgstr "" diff --git a/account_move_reconcile_forbid_cancel/i18n/es.po b/account_move_reconcile_forbid_cancel/i18n/es.po new file mode 100644 index 00000000..0ccece22 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/i18n/es.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_reconcile_forbid_cancel +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-06-20 14:20+0000\n" +"PO-Revision-Date: 2022-06-29 14:50+0000\n" +"Last-Translator: Ernesto Tejeda \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: account_move_reconcile_forbid_cancel +#: model:ir.model,name:account_move_reconcile_forbid_cancel.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_move_reconcile_forbid_cancel +#: code:addons/account_move_reconcile_forbid_cancel/models/account_move.py:0 +#, python-format +msgid "You cannot cancel reconciled entries." +msgstr "No puede cancelar asientos conciliados" + +#. module: account_move_reconcile_forbid_cancel +#: code:addons/account_move_reconcile_forbid_cancel/models/account_move.py:0 +#, python-format +msgid "You cannot reset to draft reconciled entries." +msgstr "No puede cambiar a borrador asientos conciliados" + +#~ msgid "Journal Entries" +#~ msgstr "Asientos contables" diff --git a/account_move_reconcile_forbid_cancel/i18n/pt_BR.po b/account_move_reconcile_forbid_cancel/i18n/pt_BR.po new file mode 100644 index 00000000..274a07b7 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/i18n/pt_BR.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_reconcile_forbid_cancel +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-03-17 22:25+0000\n" +"Last-Translator: Douglas Custódio \n" +"Language-Team: none\n" +"Language: pt_BR\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 4.14.1\n" + +#. module: account_move_reconcile_forbid_cancel +#: model:ir.model,name:account_move_reconcile_forbid_cancel.model_account_move +msgid "Journal Entry" +msgstr "Lançamento de Diário" + +#. module: account_move_reconcile_forbid_cancel +#: code:addons/account_move_reconcile_forbid_cancel/models/account_move.py:0 +#, python-format +msgid "You cannot cancel reconciled entries." +msgstr "Você não pode cancelar lançamentos reconciliados." + +#. module: account_move_reconcile_forbid_cancel +#: code:addons/account_move_reconcile_forbid_cancel/models/account_move.py:0 +#, python-format +msgid "You cannot reset to draft reconciled entries." +msgstr "Você não pode redefinir para rascunho lançamentos reconciliados." diff --git a/account_move_reconcile_forbid_cancel/models/__init__.py b/account_move_reconcile_forbid_cancel/models/__init__.py new file mode 100644 index 00000000..0c439503 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import account_move diff --git a/account_move_reconcile_forbid_cancel/models/account_move.py b/account_move_reconcile_forbid_cancel/models/account_move.py new file mode 100644 index 00000000..539ae708 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/models/account_move.py @@ -0,0 +1,29 @@ +# Copyright 2022 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, models, tools +from odoo.exceptions import ValidationError + + +class AccountMove(models.Model): + _inherit = "account.move" + + def button_draft(self): + if not self.env.context.get("skip_reconcile_forbid_cancel") and ( + not tools.config["test_enable"] + or self.env.context.get("test_reconcile_forbid_cancel") + ): + if self._get_reconciled_amls(): + raise ValidationError( + _("You cannot reset to draft reconciled entries.") + ) + return super().button_draft() + + def button_cancel(self): + if not self.env.context.get("skip_reconcile_forbid_cancel") and ( + not tools.config["test_enable"] + or self.env.context.get("test_reconcile_forbid_cancel") + ): + if self._get_reconciled_amls(): + raise ValidationError(_("You cannot cancel reconciled entries.")) + return super().button_cancel() diff --git a/account_move_reconcile_forbid_cancel/readme/CONTRIBUTORS.rst b/account_move_reconcile_forbid_cancel/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b31cef32 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza diff --git a/account_move_reconcile_forbid_cancel/readme/DESCRIPTION.rst b/account_move_reconcile_forbid_cancel/readme/DESCRIPTION.rst new file mode 100644 index 00000000..3c3b9cb1 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module restricts to cancel or reset to draft any invoice/journal entry that +has been reconciled (aka paid). diff --git a/account_move_reconcile_forbid_cancel/readme/USAGE.rst b/account_move_reconcile_forbid_cancel/readme/USAGE.rst new file mode 100644 index 00000000..1af82fea --- /dev/null +++ b/account_move_reconcile_forbid_cancel/readme/USAGE.rst @@ -0,0 +1,7 @@ +To use this module, you need to: + +#. Go to *Invoicing > Customers > Invoices* +#. Access an invoice that has a payment. +#. Click on the 'Reset to Draft' button and you will get an error + message to prevent you from resetting the invoice to draft state because + it has already an associated payment. diff --git a/account_move_reconcile_forbid_cancel/static/description/icon.png b/account_move_reconcile_forbid_cancel/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_move_reconcile_forbid_cancel/static/description/icon.png differ diff --git a/account_move_reconcile_forbid_cancel/static/description/index.html b/account_move_reconcile_forbid_cancel/static/description/index.html new file mode 100644 index 00000000..88309fc1 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Account Move Reconcile Forbid Cancel + + + +
+

Account Move Reconcile Forbid Cancel

+ + +

Beta License: AGPL-3 OCA/account-reconcile Translate me on Weblate Try me on Runbot

+

This module restricts to cancel or reset to draft any invoice/journal entry that +has been reconciled (aka paid).

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Invoicing > Customers > Invoices
  2. +
  3. Access an invoice that has a payment.
  4. +
  5. Click on the ‘Reset to Draft’ button and you will get an error +message to prevent you from resetting the invoice to draft state because +it has already an associated payment.
  6. +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Ernesto Tejeda
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

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/account-reconcile project on GitHub.

+

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

+
+
+
+ + diff --git a/account_move_reconcile_forbid_cancel/tests/__init__.py b/account_move_reconcile_forbid_cancel/tests/__init__.py new file mode 100644 index 00000000..3289f35f --- /dev/null +++ b/account_move_reconcile_forbid_cancel/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_account_move_reconcile_forbid_cancel diff --git a/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py b/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py new file mode 100644 index 00000000..3ed4ca79 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py @@ -0,0 +1,122 @@ +# Copyright 2022 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.exceptions import ValidationError +from odoo.tests.common import Form, TransactionCase + + +class TestAccountMoveReconcileForbidCancel(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env["account.journal"].create( + {"name": "Bank Journal", "code": "BANK", "type": "bank"} + ) + receivable_account = cls.env["account.account"].create( + { + "name": "Receivable Account", + "code": "REC", + "account_type": "asset_receivable", + "reconcile": True, + } + ) + payable_account = cls.env["account.account"].create( + { + "name": "Payable Account", + "code": "PAY", + "account_type": "liability_payable", + "reconcile": True, + } + ) + income_account = cls.env["account.account"].create( + { + "name": "Income Account", + "code": "INC", + "account_type": "income", + "reconcile": False, + } + ) + expense_account = cls.env["account.account"].create( + { + "name": "Expense Account", + "code": "EXP", + "account_type": "expense", + "reconcile": False, + } + ) + cls.partner = cls.env["res.partner"].create( + { + "name": "Partner test", + "property_account_receivable_id": receivable_account.id, + "property_account_payable_id": payable_account.id, + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Product Test", + "property_account_income_id": income_account.id, + "property_account_expense_id": expense_account.id, + } + ) + # Create a purchase invoice + cls.purchase_invoice = cls._create_invoice(cls, "in_invoice") + cls.purchase_invoice.action_post() + # Create payment from invoice + cls._create_payment_from_invoice(cls, cls.purchase_invoice) + # Create a sale invoice + cls.sale_invoice = cls._create_invoice(cls, "out_invoice") + cls.sale_invoice.action_post() + # Create payment from invoice + cls._create_payment_from_invoice(cls, cls.sale_invoice) + + def _create_invoice(self, move_type): + move_form = Form( + self.env["account.move"].with_context(default_move_type=move_type) + ) + move_form.invoice_date = fields.Date.today() + move_form.partner_id = self.partner + with move_form.invoice_line_ids.new() as line_form: + line_form.product_id = self.product + line_form.price_unit = 100.0 + return move_form.save() + + def _create_payment_from_invoice(self, invoice): + res = invoice.action_register_payment() + payment_register_form = Form( + self.env[res["res_model"]].with_context(**res["context"]) + ) + payment = payment_register_form.save() + payment.action_create_payments() + + def test_reset_invoice_to_draft(self): + with self.assertRaises(ValidationError): + self.purchase_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_draft() + with self.assertRaises(ValidationError): + self.sale_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_draft() + + def test_cancel_invoice(self): + with self.assertRaises(ValidationError): + self.purchase_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_cancel() + with self.assertRaises(ValidationError): + self.sale_invoice.with_context( + test_reconcile_forbid_cancel=True + ).button_cancel() + + def test_extra_invoice_process_to_draft(self): + invoice = self._create_invoice("out_invoice") + invoice.action_post() + invoice.button_draft() + self.assertEqual(invoice.state, "draft") + + def test_extra_invoice_process_cancel(self): + invoice = self._create_invoice("out_invoice") + invoice.action_post() + invoice.button_cancel() + self.assertEqual(invoice.state, "cancel") diff --git a/setup/account_move_reconcile_forbid_cancel/odoo/addons/account_move_reconcile_forbid_cancel b/setup/account_move_reconcile_forbid_cancel/odoo/addons/account_move_reconcile_forbid_cancel new file mode 120000 index 00000000..158970bc --- /dev/null +++ b/setup/account_move_reconcile_forbid_cancel/odoo/addons/account_move_reconcile_forbid_cancel @@ -0,0 +1 @@ +../../../../account_move_reconcile_forbid_cancel \ No newline at end of file diff --git a/setup/account_move_reconcile_forbid_cancel/setup.py b/setup/account_move_reconcile_forbid_cancel/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_move_reconcile_forbid_cancel/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)