diff --git a/account_move_reconcile_forbid_cancel/README.rst b/account_move_reconcile_forbid_cancel/README.rst new file mode 100644 index 00000000..7d3629d2 --- /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/13.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-13-0/account-reconcile-13-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/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of account invoicing to restrict +'reset to draft' or 'cancel' an invoice that has been reconciled. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to *Invoicing > Customers > invoices* +#. Edit an invoice that has a payment. +#. Click the 'Reset to Draft' button and you will get a validation error + message to prevent you from resetting the invoice to draft state because + it already has 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..4f42f6ea --- /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": "13.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..dc6d9f36 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/i18n/account_move_reconcile_forbid_cancel.pot @@ -0,0 +1,33 @@ +# 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-20 14:20+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_move_reconcile_forbid_cancel +#: model:ir.model,name:account_move_reconcile_forbid_cancel.model_account_move +msgid "Journal 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 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..79cf1e08 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/i18n/es.po @@ -0,0 +1,35 @@ +# 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-20 10:29-0400\n" +"Last-Translator: \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: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: account_move_reconcile_forbid_cancel +#: model:ir.model,name:account_move_reconcile_forbid_cancel.model_account_move +msgid "Journal Entries" +msgstr "Asientos contables" + +#. 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 conciliadas" 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..4e67dfd9 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/models/account_move.py @@ -0,0 +1,26 @@ +# Copyright 2022 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, models +from odoo.exceptions import ValidationError + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _get_receivable_payable_lines(self): + return self.line_ids.filtered( + lambda l: l.account_internal_type in ["receivable", "acc_type_pay"], + ) + + def button_draft(self): + rec_pay_lines = self._get_receivable_payable_lines() + if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids: + raise ValidationError(_("You cannot reset to draft reconciled entries.")) + super().button_draft() + + def button_cancel(self): + rec_pay_lines = self._get_receivable_payable_lines() + if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids: + raise ValidationError(_("You cannot cancel reconciled entries.")) + 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/index.html b/account_move_reconcile_forbid_cancel/static/description/index.html new file mode 100644 index 00000000..97f9df75 --- /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 extends the functionality of account invoicing to restrict +‘reset to draft’ or ‘cancel’ an invoice that has been reconciled.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Invoicing > Customers > invoices
  2. +
  3. Edit an invoice that has a payment.
  4. +
  5. Click the ‘Reset to Draft’ button and you will get a validation error +message to prevent you from resetting the invoice to draft state because +it already has 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..3edb3c68 --- /dev/null +++ b/account_move_reconcile_forbid_cancel/tests/test_account_move_reconcile_forbid_cancel.py @@ -0,0 +1,83 @@ +# Copyright 2022 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.tests.common import Form, SavepointCase + + +class TestAccountMoveReconcileForbidCancel(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + journal_sale = cls.env["account.journal"].create( + {"name": "Sale journal", "code": "SJ", "type": "sale"} + ) + receivable_account_type = cls.env["account.account.type"].create( + { + "name": "Receivable account type", + "type": "receivable", + "internal_group": "asset", + } + ) + income_account_type = cls.env["account.account.type"].create( + { + "name": "Income account type", + "type": "other", + "internal_group": "income", + } + ) + receivable_account = cls.env["account.account"].create( + { + "name": "Receivable Account", + "code": "REC", + "user_type_id": receivable_account_type.id, + "reconcile": True, + } + ) + income_account = cls.env["account.account"].create( + { + "name": "Income Account", + "code": "INC", + "user_type_id": income_account_type.id, + "reconcile": False, + } + ) + partner = cls.env["res.partner"].create( + { + "name": "Partner test", + "property_account_receivable_id": receivable_account.id, + } + ) + product = cls.env["product.product"].create( + {"name": "Product Test", "property_account_income_id": income_account.id} + ) + # Create invoice + move_form = Form( + cls.env["account.move"].with_context(default_type="out_invoice") + ) + move_form.journal_id = journal_sale + move_form.partner_id = partner + with move_form.invoice_line_ids.new() as line_form: + line_form.product_id = product + line_form.price_unit = 100.0 + cls.invoice = move_form.save() + cls.invoice.action_post() + # Create payment from invoice + cls.env["account.journal"].create( + {"name": "Bank Journal", "code": "BANK", "type": "bank"} + ) + payment_register = Form( + cls.env["account.payment"].with_context( + active_model="account.move", active_ids=cls.invoice.ids, + ) + ) + cls.payment = payment_register.save() + cls.payment.post() + + def test_reset_invoice_to_draft(self): + with self.assertRaises(ValidationError): + self.invoice.button_draft() + + def test_cancel_invoice(self): + with self.assertRaises(ValidationError): + self.invoice.button_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, +)