diff --git a/account_move_cancel_confirm/README.rst b/account_move_cancel_confirm/README.rst new file mode 100644 index 00000000000..3f7bd8d1590 --- /dev/null +++ b/account_move_cancel_confirm/README.rst @@ -0,0 +1,87 @@ +=========================== +Account Move Cancel Confirm +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6d9331c29140b523ccb8fc453786dcfb6f74b4037119c36c0fe65d26b0eb1dea + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--invoicing-lightgray.png?logo=github + :target: https://github.com/OCA/account-invoicing/tree/16.0/account_move_cancel_confirm + :alt: OCA/account-invoicing +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-invoicing-16-0/account-invoicing-16-0-account_move_cancel_confirm + :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/account-invoicing&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When user click to cancel invoice and journal entry, a confirmation wizard will be show, with reason as optional. + +For information on how to enable the feature, refer to the Configuration of the module *base_cancel_confirm*. + +**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 +~~~~~~~ + +* Ecosoft + +Contributors +~~~~~~~~~~~~ + +* Kitti U. +* Jordi Masvidal + +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-kittiu| image:: https://github.com/kittiu.png?size=40px + :target: https://github.com/kittiu + :alt: kittiu + +Current `maintainer `__: + +|maintainer-kittiu| + +This module is part of the `OCA/account-invoicing `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_cancel_confirm/__init__.py b/account_move_cancel_confirm/__init__.py new file mode 100644 index 00000000000..02c244eef06 --- /dev/null +++ b/account_move_cancel_confirm/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import model diff --git a/account_move_cancel_confirm/__manifest__.py b/account_move_cancel_confirm/__manifest__.py new file mode 100644 index 00000000000..eb203a37f78 --- /dev/null +++ b/account_move_cancel_confirm/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Move Cancel Confirm", + "version": "12.0.1.0.0", + "author": "Ecosoft, Odoo Community Association (OCA)", + "category": "Usability", + "license": "AGPL-3", + "website": "https://github.com/OCA/account-invoicing", + "depends": ["base_cancel_confirm", "account"], + "installable": True, + "maintainers": ["kittiu"], +} diff --git a/account_move_cancel_confirm/i18n/account_move_cancel_confirm.pot b/account_move_cancel_confirm/i18n/account_move_cancel_confirm.pot new file mode 100644 index 00000000000..a8ba06cfab9 --- /dev/null +++ b/account_move_cancel_confirm/i18n/account_move_cancel_confirm.pot @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_cancel_confirm +# +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_move_cancel_confirm +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_move__cancel_confirm +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_payment__cancel_confirm +msgid "A flag signify that this document is confirmed for cancellation" +msgstr "" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_move__cancel_reason +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_payment__cancel_reason +msgid "An optional cancel reason" +msgstr "" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_move__cancel_confirm +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_payment__cancel_confirm +msgid "Cancel Confirmed" +msgstr "" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_move__cancel_reason +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_payment__cancel_reason +msgid "Cancel Reason" +msgstr "" + +#. module: account_move_cancel_confirm +#: model:ir.model,name:account_move_cancel_confirm.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_move_cancel_confirm +#: model:ir.model,name:account_move_cancel_confirm.model_account_payment +msgid "Payments" +msgstr "" diff --git a/account_move_cancel_confirm/i18n/it.po b/account_move_cancel_confirm/i18n/it.po new file mode 100644 index 00000000000..3f56b57ca0d --- /dev/null +++ b/account_move_cancel_confirm/i18n/it.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_cancel_confirm +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-08-07 17:58+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.6.2\n" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_move__cancel_confirm +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_payment__cancel_confirm +msgid "A flag signify that this document is confirmed for cancellation" +msgstr "Una spunta indica che questo documento รจ confermato per l'annullamento" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_move__cancel_reason +#: model:ir.model.fields,help:account_move_cancel_confirm.field_account_payment__cancel_reason +msgid "An optional cancel reason" +msgstr "Un motivo di annullamento opzionale" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_move__cancel_confirm +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_payment__cancel_confirm +msgid "Cancel Confirmed" +msgstr "Annullamento confermato" + +#. module: account_move_cancel_confirm +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_move__cancel_reason +#: model:ir.model.fields,field_description:account_move_cancel_confirm.field_account_payment__cancel_reason +msgid "Cancel Reason" +msgstr "Causale annullamento" + +#. module: account_move_cancel_confirm +#: model:ir.model,name:account_move_cancel_confirm.model_account_move +msgid "Journal Entry" +msgstr "Registrazione contabile" + +#. module: account_move_cancel_confirm +#: model:ir.model,name:account_move_cancel_confirm.model_account_payment +msgid "Payments" +msgstr "Pagamenti" diff --git a/account_move_cancel_confirm/model/__init__.py b/account_move_cancel_confirm/model/__init__.py new file mode 100644 index 00000000000..aca8a399839 --- /dev/null +++ b/account_move_cancel_confirm/model/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import account_invoice +from . import account_move +from . import account_payment diff --git a/account_move_cancel_confirm/model/account_invoice.py b/account_move_cancel_confirm/model/account_invoice.py new file mode 100644 index 00000000000..06045708783 --- /dev/null +++ b/account_move_cancel_confirm/model/account_invoice.py @@ -0,0 +1,30 @@ +# Copyright 2024 ForgeFlow +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AccountInvoice(models.Model): + _name = "account.invoice" + _inherit = ["account.invoice", "base.cancel.confirm"] + + _has_cancel_reason = "optional" # ["no", "optional", "required"] + + def action_invoice_cancel(self): + cancel_res_model = self.env.context.get("cancel_res_model", False) + cancel_res_ids = self.env.context.get("cancel_res_ids", False) + cancel_method = self.env.context.get("cancel_method", False) + # cancel from payment + if cancel_res_model == "account.payment" and cancel_method == "action_cancel": + docs = self.env[cancel_res_model].browse(cancel_res_ids) + cancel_reason = ", ".join( + docs.filtered("cancel_reason").mapped("cancel_reason") + ) + self.write({"cancel_confirm": True, "cancel_reason": cancel_reason}) + if not self.filtered("cancel_confirm"): + return self.open_cancel_confirm_wizard() + return super().action_invoice_cancel() + + def action_invoice_draft(self): + self.clear_cancel_confirm_data() + return super().action_invoice_draft() diff --git a/account_move_cancel_confirm/model/account_move.py b/account_move_cancel_confirm/model/account_move.py new file mode 100644 index 00000000000..d1079f8384a --- /dev/null +++ b/account_move_cancel_confirm/model/account_move.py @@ -0,0 +1,30 @@ +# Copyright 2020 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AccountMove(models.Model): + _name = "account.move" + _inherit = ["account.move", "base.cancel.confirm"] + + _has_cancel_reason = "optional" # ["no", "optional", "required"] + + def button_cancel(self): + cancel_res_model = self.env.context.get("cancel_res_model", False) + cancel_res_ids = self.env.context.get("cancel_res_ids", False) + cancel_method = self.env.context.get("cancel_method", False) + # cancel from payment + if cancel_res_model == "account.payment" and cancel_method == "cancel": + docs = self.env[cancel_res_model].browse(cancel_res_ids) + cancel_reason = ", ".join( + docs.filtered("cancel_reason").mapped("cancel_reason") + ) + self.write({"cancel_confirm": True, "cancel_reason": cancel_reason}) + if not self.filtered("cancel_confirm"): + return self.open_cancel_confirm_wizard() + return super().button_cancel() + + def button_draft(self): + self.clear_cancel_confirm_data() + return super().button_draft() diff --git a/account_move_cancel_confirm/model/account_payment.py b/account_move_cancel_confirm/model/account_payment.py new file mode 100644 index 00000000000..3265b214490 --- /dev/null +++ b/account_move_cancel_confirm/model/account_payment.py @@ -0,0 +1,20 @@ +# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AccountPayment(models.Model): + _name = "account.payment" + _inherit = ["account.payment", "base.cancel.confirm"] + + _has_cancel_reason = "optional" # ["no", "optional", "required"] + + def cancel(self): + if not self.filtered("cancel_confirm"): + return self.open_cancel_confirm_wizard() + return super().cancel() + + def action_draft(self): + self.clear_cancel_confirm_data() + return super().action_draft() diff --git a/account_move_cancel_confirm/readme/CONTRIBUTORS.rst b/account_move_cancel_confirm/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..dd1f9de5a29 --- /dev/null +++ b/account_move_cancel_confirm/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Kitti U. +* Jordi Masvidal +* Guillem Casassas diff --git a/account_move_cancel_confirm/readme/DESCRIPTION.rst b/account_move_cancel_confirm/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..8271ae7ef74 --- /dev/null +++ b/account_move_cancel_confirm/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +When user click to cancel invoice and journal entry, a confirmation wizard will be show, with reason as optional. + +For information on how to enable the feature, refer to the Configuration of the module *base_cancel_confirm*. diff --git a/account_move_cancel_confirm/static/description/icon.png b/account_move_cancel_confirm/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_move_cancel_confirm/static/description/icon.png differ diff --git a/account_move_cancel_confirm/static/description/index.html b/account_move_cancel_confirm/static/description/index.html new file mode 100644 index 00000000000..bc8fb5ed527 --- /dev/null +++ b/account_move_cancel_confirm/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Account Move Cancel Confirm + + + +
+

Account Move Cancel Confirm

+ + +

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

+

When user click to cancel invoice and journal entry, a confirmation wizard will be show, with reason as optional.

+

For information on how to enable the feature, refer to the Configuration of the module base_cancel_confirm.

+

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

+
    +
  • Ecosoft
  • +
+
+
+

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 maintainer:

+

kittiu

+

This module is part of the OCA/account-invoicing project on GitHub.

+

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

+
+
+
+ + diff --git a/account_move_cancel_confirm/tests/__init__.py b/account_move_cancel_confirm/tests/__init__.py new file mode 100644 index 00000000000..7b96be289e4 --- /dev/null +++ b/account_move_cancel_confirm/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_account_move_cancel_confirm diff --git a/account_move_cancel_confirm/tests/test_account_move_cancel_confirm.py b/account_move_cancel_confirm/tests/test_account_move_cancel_confirm.py new file mode 100644 index 00000000000..6e0aa306c0f --- /dev/null +++ b/account_move_cancel_confirm/tests/test_account_move_cancel_confirm.py @@ -0,0 +1,120 @@ +# Copyright 2022 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestAccountMoveCancelConfirm(TransactionCase): + def setUp(self): + super().setUp() + self.account_invoice_model = self.env["account.invoice"] + self.register_payments_model = self.env["account.register.payments"] + self.payment_model = self.env["account.payment"] + self.partner = self.env.ref("base.res_partner_2") + self.product = self.env.ref("product.product_product_7") + self.payment_method_manual_in = self.env.ref( + "account.account_payment_method_manual_in" + ) + # Add parameter with cancel confirm + self.env["ir.config_parameter"].create( + {"key": "account.invoice.cancel_confirm_disable", "value": "False"} + ) + self.env["ir.config_parameter"].create( + {"key": "account.move.cancel_confirm_disable", "value": "False"} + ) + self.env["ir.config_parameter"].create( + {"key": "account.payment.cancel_confirm_disable", "value": "False"} + ) + self.journal_bank = self.env["account.journal"].create( + { + "name": "Bank", + "type": "bank", + "code": "BNK67", + "update_posted": True + } + ) + self.income_account = self.env["account.account"].create({ + "code": "INC", + "name": "revenue account", + "user_type_id": self.env.ref("account.data_account_type_revenue").id, + }) + self.invoice = self.account_invoice_model.create( + { + "partner_id": self.partner.id, + "journal_id": self.journal_bank.id, + "date_invoice": fields.Date.today(), + "type": "in_invoice", + "invoice_line_ids": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "price_unit": 100.0, + "name": self.product.name, + "account_id": self.income_account.id + } + ) + ], + } + ) + + def test_01_cancel_invoice(self): + """ + - Cancel a account invoice with the wizard asking for the reason + - Then the account invoice should be canceled and the reason stored + """ + # Click cancel, cancel confirm wizard will open. Type in cancel_reason + res = self.invoice.action_invoice_cancel() + ctx = res.get("context") + self.assertEqual(ctx["cancel_method"], "action_invoice_cancel") + self.assertEqual(ctx["default_has_cancel_reason"], "optional") + wizard = Form(self.env["cancel.confirm"].with_context(**ctx)) + wizard.cancel_reason = "Wrong information" + wiz = wizard.save() + # Confirm cancel on wizard + wiz.confirm_cancel() + self.assertEqual(self.invoice.cancel_reason, wizard.cancel_reason) + self.assertEqual(self.invoice.state, "cancel") + # Set to draft + self.invoice.action_invoice_draft() + self.assertEqual(self.invoice.cancel_reason, False) + + def test_02_cancel_payment(self): + """ + - Cancel a payment with the wizard asking for the reason + - Then the payment should be canceled and the reason stored + """ + # Create Payment + self.invoice.action_invoice_open() + ctx = { + "active_model": "account.invoice", + "active_ids": [self.invoice.id], + } + register_payments = self.register_payments_model.with_context( + ctx + ).create({ + "journal_id": self.journal_bank.id, + "payment_method_id": self.payment_method_manual_in.id, + }) + register_payments.create_payments() + payment = self.payment_model.search([], order="id desc", limit=1) + self.assertEqual(payment.state, "posted") + # Click cance, cancel confirm wizard will open. Type in cancel_reason + res = payment.cancel() + ctx = res.get("context") + self.assertEqual(ctx["cancel_method"], "cancel") + self.assertEqual(ctx["default_has_cancel_reason"], "optional") + wizard = Form(self.env["cancel.confirm"].with_context(**ctx)) + wizard.cancel_reason = "Wrong information" + wiz = wizard.save() + # Confirm cancel on wizard + wiz.confirm_cancel() + self.assertEqual(payment.cancel_reason, wizard.cancel_reason) + self.assertEqual(payment.state, "cancelled") + # Set to draft + payment.action_draft() + self.assertEqual(payment.cancel_reason, False) + self.assertEqual(payment.state, "draft") diff --git a/setup/account_move_cancel_confirm/odoo/addons/account_move_cancel_confirm b/setup/account_move_cancel_confirm/odoo/addons/account_move_cancel_confirm new file mode 120000 index 00000000000..5efa21e8b92 --- /dev/null +++ b/setup/account_move_cancel_confirm/odoo/addons/account_move_cancel_confirm @@ -0,0 +1 @@ +../../../../account_move_cancel_confirm \ No newline at end of file diff --git a/setup/account_move_cancel_confirm/setup.py b/setup/account_move_cancel_confirm/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_move_cancel_confirm/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..2456ba571f6 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +# [12.0][BKP] base_cancel_confirm +odoo12-addon-base_cancel_confirm@git+https://github.com/ForgeFlow/server-ux.git@12.0-bkp-base_cancel_confirm#subdirectory=setup/base_cancel_confirm +