[MIG] mrp_production_back_to_draft: Migration to 17.0

This commit is contained in:
Meritxell Abellan
2024-12-17 13:32:48 +01:00
parent 9688350043
commit 18fa1a1ff1
4 changed files with 23 additions and 8 deletions

View File

@@ -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",

View File

@@ -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
@@ -22,3 +22,19 @@ class MrpProduction(models.Model):
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

View File

@@ -7,13 +7,12 @@ from odoo.tests import common, tagged
@tagged("post_install", "-at_install")
class TestMrpProductionAutovalidate(common.SavepointCase):
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.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(
@@ -68,19 +67,19 @@ class TestMrpProductionAutovalidate(common.SavepointCase):
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")

View File

@@ -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>