Skip to content

Commit

Permalink
[MIG] mrp_production_back_to_draft: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MeritxellAForgeFlow committed Dec 17, 2024
1 parent 9688350 commit 3d37c87
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mrp_production_back_to_draft/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "MRP Production Back to Draft",
"version": "14.0.1.0.1",
"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",
Expand Down
17 changes: 16 additions & 1 deletion mrp_production_back_to_draft/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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 import _, api, models
from odoo.exceptions import UserError


Expand All @@ -22,3 +22,18 @@ def action_return_to_draft(self):
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"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@tagged("post_install", "-at_install")
class TestMrpProductionAutovalidate(common.SavepointCase):
class TestMrpProductionAutovalidate(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -68,19 +68,19 @@ def test_01_mrp_return_to_draft(self):
self.prod_ti1, self.location, 2
)
self.assertEqual(self.mo_1.state, "draft")
self.mo_1._onchange_move_raw()
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._onchange_move_raw()
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._onchange_move_raw()
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
type="object"
class="oe_stat_button"
string="Return to Draft"
attrs="{'invisible': [('state', 'not in', ['confirmed', 'cancel'])]}"
invisible="state not in ['confirmed', 'cancel']"
>
</button>
</button>
Expand Down

0 comments on commit 3d37c87

Please sign in to comment.