diff --git a/mrp_production_back_to_draft/README.rst b/mrp_production_back_to_draft/README.rst new file mode 100644 index 000000000..fa3c717f7 --- /dev/null +++ b/mrp_production_back_to_draft/README.rst @@ -0,0 +1,76 @@ +============================ +MRP Production Back to Draft +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:759dd0cf5f18855c3a050e5796eda3ee2f65ed6df213e9a88b8991303e53a33b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/17.0/mrp_production_back_to_draft + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-17-0/manufacture-17-0-mrp_production_back_to_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/manufacture&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to return to draft a confirmed or cancelled MO. + +**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 +------- + +* ForgeFlow + +Contributors +------------ + +- David Jiménez + +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/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_production_back_to_draft/__init__.py b/mrp_production_back_to_draft/__init__.py new file mode 100644 index 000000000..638f0c9a4 --- /dev/null +++ b/mrp_production_back_to_draft/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mrp_production_back_to_draft/__manifest__.py b/mrp_production_back_to_draft/__manifest__.py new file mode 100644 index 000000000..56ee943a8 --- /dev/null +++ b/mrp_production_back_to_draft/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "MRP Production Back to Draft", + "version": "17.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "summary": "Allows to return to draft a confirmed or cancelled MO.", + "website": "https://github.com/OCA/manufacture", + "category": "Manufacturing/Manufacturing", + "license": "AGPL-3", + "depends": ["mrp"], + "data": [ + "views/mrp_production_views.xml", + ], + "installable": True, +} diff --git a/mrp_production_back_to_draft/i18n/it.po b/mrp_production_back_to_draft/i18n/it.po new file mode 100644 index 000000000..22b3d426b --- /dev/null +++ b/mrp_production_back_to_draft/i18n/it.po @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_back_to_draft +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\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" + +#. module: mrp_production_back_to_draft +#: model:ir.model.fields,field_description:mrp_production_back_to_draft.field_mrp_production__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model:ir.model.fields,field_description:mrp_production_back_to_draft.field_mrp_production__id +msgid "ID" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model:ir.model.fields,field_description:mrp_production_back_to_draft.field_mrp_production____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model:ir.model,name:mrp_production_back_to_draft.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model_terms:ir.ui.view,arch_db:mrp_production_back_to_draft.mrp_production_form_view_return_to_draft +msgid "Return to Draft" +msgstr "" + +#. module: mrp_production_back_to_draft +#: code:addons/mrp_production_back_to_draft/models/mrp_production.py:0 +#, python-format +msgid "" +"You cannot return to draft the following MO: %s. Only confirmed or cancelled" +" MO can be returned to draft." +msgstr "" diff --git a/mrp_production_back_to_draft/i18n/mrp_production_back_to_draft.pot b/mrp_production_back_to_draft/i18n/mrp_production_back_to_draft.pot new file mode 100644 index 000000000..3afe3eac2 --- /dev/null +++ b/mrp_production_back_to_draft/i18n/mrp_production_back_to_draft.pot @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_back_to_draft +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: mrp_production_back_to_draft +#: model:ir.model.fields,field_description:mrp_production_back_to_draft.field_mrp_production__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model:ir.model.fields,field_description:mrp_production_back_to_draft.field_mrp_production__id +msgid "ID" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model:ir.model.fields,field_description:mrp_production_back_to_draft.field_mrp_production____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model:ir.model,name:mrp_production_back_to_draft.model_mrp_production +msgid "Production Order" +msgstr "" + +#. module: mrp_production_back_to_draft +#: model_terms:ir.ui.view,arch_db:mrp_production_back_to_draft.mrp_production_form_view_return_to_draft +msgid "Return to Draft" +msgstr "" + +#. module: mrp_production_back_to_draft +#: code:addons/mrp_production_back_to_draft/models/mrp_production.py:0 +#, python-format +msgid "" +"You cannot return to draft the following MO: %s. Only confirmed or cancelled" +" MO can be returned to draft." +msgstr "" diff --git a/mrp_production_back_to_draft/models/__init__.py b/mrp_production_back_to_draft/models/__init__.py new file mode 100644 index 000000000..59d2f0e1c --- /dev/null +++ b/mrp_production_back_to_draft/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import mrp_production diff --git a/mrp_production_back_to_draft/models/mrp_production.py b/mrp_production_back_to_draft/models/mrp_production.py new file mode 100644 index 000000000..500d6e4a7 --- /dev/null +++ b/mrp_production_back_to_draft/models/mrp_production.py @@ -0,0 +1,40 @@ +# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import UserError + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + def action_return_to_draft(self): + self._check_company() + for rec in self: + if rec.state not in ["confirmed", "cancel"]: + raise UserError( + _( + "You cannot return to draft the following MO: %s. " + "Only confirmed or cancelled MO can be returned to draft." + ) + % rec.name + ) + else: + (rec.move_raw_ids + rec.move_finished_ids)._action_cancel() + (rec.move_raw_ids + rec.move_finished_ids).write({"state": "draft"}) + if rec.state != "draft": + raise UserError( + _("Could not set the production order back to draft") + ) + + @api.depends("move_raw_ids.state", "move_finished_ids.state") + def _compute_state(self): + super()._compute_state() + for production in self: + if ( + production.state == "cancel" + and all(m.state == "draft" for m in production.move_raw_ids) + and all(m.state == "draft" for m in production.move_finished_ids) + ): + production.state = "draft" + return diff --git a/mrp_production_back_to_draft/pyproject.toml b/mrp_production_back_to_draft/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mrp_production_back_to_draft/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mrp_production_back_to_draft/readme/CONTRIBUTORS.md b/mrp_production_back_to_draft/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..ac18283b8 --- /dev/null +++ b/mrp_production_back_to_draft/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- David Jiménez \<\> diff --git a/mrp_production_back_to_draft/readme/DESCRIPTION.md b/mrp_production_back_to_draft/readme/DESCRIPTION.md new file mode 100644 index 000000000..255387560 --- /dev/null +++ b/mrp_production_back_to_draft/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to return to draft a confirmed or cancelled MO. diff --git a/mrp_production_back_to_draft/static/description/icon.png b/mrp_production_back_to_draft/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mrp_production_back_to_draft/static/description/icon.png differ diff --git a/mrp_production_back_to_draft/static/description/index.html b/mrp_production_back_to_draft/static/description/index.html new file mode 100644 index 000000000..9cd9f74e0 --- /dev/null +++ b/mrp_production_back_to_draft/static/description/index.html @@ -0,0 +1,420 @@ + + + + + +MRP Production Back to Draft + + + +
+

MRP Production Back to Draft

+ + +

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

+

This module allows to return to draft a confirmed or cancelled MO.

+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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.

+

This module is part of the OCA/manufacture project on GitHub.

+

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

+
+
+
+ + diff --git a/mrp_production_back_to_draft/tests/__init__.py b/mrp_production_back_to_draft/tests/__init__.py new file mode 100644 index 000000000..c78046498 --- /dev/null +++ b/mrp_production_back_to_draft/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_mrp_return_to_draft diff --git a/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py b/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py new file mode 100644 index 000000000..1505b7598 --- /dev/null +++ b/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py @@ -0,0 +1,87 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api +from odoo.exceptions import UserError +from odoo.tests import common, tagged + + +@tagged("post_install", "-at_install") +class TestMrpProductionAutovalidate(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user_admin = cls.env.ref("base.user_admin") + cls.env = api.Environment(cls.cr, cls.user_admin.id, {}) + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.location = cls.env.ref("stock.stock_location_stock") + cls.env.user.write( + { + "groups_id": [ + (6, 0, cls.env.user.groups_id.ids), + (4, cls.env.ref("stock.group_stock_manager").id), + ], + } + ) + cls.prod_tp1 = cls.env["product.product"].create( + { + "name": "Test Product 1", + "type": "product", + } + ) + cls.prod_ti1 = cls.env["product.product"].create( + { + "name": "Test Product Intermediate 1", + "type": "product", + } + ) + # Create BoMs: + cls.test_bom_1 = cls.env["mrp.bom"].create( + { + "product_id": cls.prod_tp1.id, + "product_tmpl_id": cls.prod_tp1.product_tmpl_id.id, + "product_uom_id": cls.prod_tp1.uom_id.id, + "product_qty": 1.0, + "type": "normal", + } + ) + cls.env["mrp.bom.line"].create( + { + "bom_id": cls.test_bom_1.id, + "product_id": cls.prod_ti1.id, + "product_qty": 1.0, + } + ) + cls.mo_1 = cls.env["mrp.production"].create( + { + "name": "MO ABC", + "product_id": cls.prod_tp1.id, + "product_uom_id": cls.prod_tp1.uom_id.id, + "product_qty": 2, + "bom_id": cls.test_bom_1.id, + } + ) + + def test_01_mrp_return_to_draft(self): + self.env["stock.quant"]._update_available_quantity( + self.prod_ti1, self.location, 2 + ) + self.assertEqual(self.mo_1.state, "draft") + self.mo_1._compute_move_raw_ids() + self.mo_1.action_confirm() + self.assertEqual(self.mo_1.state, "confirmed") + self.mo_1.action_return_to_draft() + self.assertEqual(self.mo_1.state, "draft") + self.mo_1._compute_move_raw_ids() + self.mo_1.action_confirm() + self.assertEqual(self.mo_1.state, "confirmed") + self.mo_1.action_cancel() + self.assertEqual(self.mo_1.state, "cancel") + self.mo_1.action_return_to_draft() + self.assertEqual(self.mo_1.state, "draft") + self.mo_1._compute_move_raw_ids() + self.mo_1.action_confirm() + self.mo_1.qty_producing = 2 + self.assertEqual(self.mo_1.state, "to_close") + with self.assertRaises(UserError): + self.mo_1.action_return_to_draft() diff --git a/mrp_production_back_to_draft/views/mrp_production_views.xml b/mrp_production_back_to_draft/views/mrp_production_views.xml new file mode 100644 index 000000000..9f6dca024 --- /dev/null +++ b/mrp_production_back_to_draft/views/mrp_production_views.xml @@ -0,0 +1,24 @@ + + + + + mrp.production.form - return_to_draft + mrp.production + + + + + + +