diff --git a/mrp_production_back_to_draft/README.rst b/mrp_production_back_to_draft/README.rst new file mode 100644 index 000000000..f7647d577 --- /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:6315dac1650b1261af8b4c3a8071f794337647dad41a31f8bd15dfbe29573a99 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/14.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-14-0/manufacture-14-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=14.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..8bb2bc6f2 --- /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": "14.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/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..57c18204d --- /dev/null +++ b/mrp_production_back_to_draft/models/mrp_production.py @@ -0,0 +1,24 @@ +# 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 _, 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._action_cancel() + rec.move_raw_ids.write({"state": "draft"}) diff --git a/mrp_production_back_to_draft/readme/CONTRIBUTORS.rst b/mrp_production_back_to_draft/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..fcd081018 --- /dev/null +++ b/mrp_production_back_to_draft/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* David Jiménez diff --git a/mrp_production_back_to_draft/readme/DESCRIPTION.rst b/mrp_production_back_to_draft/readme/DESCRIPTION.rst new file mode 100644 index 000000000..255387560 --- /dev/null +++ b/mrp_production_back_to_draft/readme/DESCRIPTION.rst @@ -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..82c1ba7ed --- /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..98edd0a19 --- /dev/null +++ b/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py @@ -0,0 +1,88 @@ +# 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.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestMrpProductionAutovalidate, cls).setUpClass() + cls.user_admin = cls.env.ref("base.user_admin") + cls.env = api.Environment(cls.cr, cls.user_admin.id, {}) + cls.env.user.tz = False # Make sure there's no timezone in user + 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._onchange_move_raw() + 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._onchange_move_raw() + 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._onchange_move_raw() + 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..27cfe8b8b --- /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 + + + + + + +