diff --git a/account_move_force_removal/__init__.py b/account_move_force_removal/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_move_force_removal/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_force_removal/__manifest__.py b/account_move_force_removal/__manifest__.py new file mode 100644 index 000000000..4397bf2ba --- /dev/null +++ b/account_move_force_removal/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Account Move Force Removal", + "summary": """Allow force removal account moves""", + "version": "13.0.1.0.0", + "category": "Account", + "license": "AGPL-3", + "website": "https://github.com/OCA/account-financial-tools", + "author": "Tecnativa, Odoo Community Association (OCA)", + "depends": ["account"], +} diff --git a/account_move_force_removal/models/__init__.py b/account_move_force_removal/models/__init__.py new file mode 100644 index 000000000..3bd27c056 --- /dev/null +++ b/account_move_force_removal/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html + +from . import account_move diff --git a/account_move_force_removal/models/account_move.py b/account_move_force_removal/models/account_move.py new file mode 100644 index 000000000..9a70e7492 --- /dev/null +++ b/account_move_force_removal/models/account_move.py @@ -0,0 +1,13 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def unlink(self): + cancelled_moves = self.filtered(lambda m: m.state == "cancel") + super(AccountMove, cancelled_moves.with_context(force_delete=True)).unlink() + return super(AccountMove, self - cancelled_moves).unlink() diff --git a/account_move_force_removal/readme/CONTRIBUTORS.rst b/account_move_force_removal/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..5fb713053 --- /dev/null +++ b/account_move_force_removal/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza diff --git a/account_move_force_removal/readme/DESCRIPTION.rst b/account_move_force_removal/readme/DESCRIPTION.rst new file mode 100644 index 000000000..5f0c79047 --- /dev/null +++ b/account_move_force_removal/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows you to delete account moves, which is prevented in Odoo by default. +You must care yourself about the numbering sequence doing this. diff --git a/account_move_force_removal/readme/USAGE.rst b/account_move_force_removal/readme/USAGE.rst new file mode 100644 index 000000000..6d501c3ca --- /dev/null +++ b/account_move_force_removal/readme/USAGE.rst @@ -0,0 +1,4 @@ +#. Go to Invoicing > Customers > Invoices and enter an invoice. +#. Click on "Reset to draft" +#. Click on "Cancel entry +#. Try to delete invoice diff --git a/account_move_force_removal/static/description/icon.png b/account_move_force_removal/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_move_force_removal/static/description/icon.png differ diff --git a/account_move_force_removal/tests/__init__.py b/account_move_force_removal/tests/__init__.py new file mode 100644 index 000000000..a7aa32c01 --- /dev/null +++ b/account_move_force_removal/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import test_move diff --git a/account_move_force_removal/tests/test_move.py b/account_move_force_removal/tests/test_move.py new file mode 100644 index 000000000..7fee734ec --- /dev/null +++ b/account_move_force_removal/tests/test_move.py @@ -0,0 +1,52 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html + +from odoo.exceptions import UserError +from odoo.tests import Form +from odoo.tests.common import SavepointCase + + +class TestMove(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create( + {"name": "Test customer", "customer_rank": 1} + ) + cls.journal = cls.env["account.journal"].create( + { + "name": "Test journal", + "type": "sale", + "code": "test-sale-jorunal", + "company_id": cls.env.company.id, + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Test product", "type": "service"} + ) + invoice = Form( + cls.env["account.move"].with_context( + default_type="out_invoice", default_company_id=cls.env.company.id + ) + ) + invoice.partner_id = cls.partner + invoice.journal_id = cls.journal + with invoice.invoice_line_ids.new() as line_form: + line_form.name = cls.product.name + line_form.product_id = cls.product + line_form.quantity = 1.0 + line_form.price_unit = 10 + invoice = invoice.save() + invoice.action_post() + cls.invoice = invoice + + def test_remove_invoice_error(self): + # Delete invoice while name isn't / + with self.assertRaises(UserError): + self.invoice.unlink() + + def test_ok_invoice_error(self): + # Delete invoice (previously draft + camcel) + self.invoice.button_draft() + self.invoice.button_cancel() + self.invoice.unlink() diff --git a/setup/account_move_force_removal/odoo/addons/account_move_force_removal b/setup/account_move_force_removal/odoo/addons/account_move_force_removal new file mode 120000 index 000000000..c240a17f3 --- /dev/null +++ b/setup/account_move_force_removal/odoo/addons/account_move_force_removal @@ -0,0 +1 @@ +../../../../account_move_force_removal \ No newline at end of file diff --git a/setup/account_move_force_removal/setup.py b/setup/account_move_force_removal/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_move_force_removal/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)