[FIX] mrp: successively plan/unplan the same mo
Introduces by #0679d0d54269ffe0664845e8e0bd1238110fd514 when you plan a workorder, the corresponding workcenter will reserve a leave to avoid to plan an another workorder in the same time slot. But before this commit, when you unplan your workorder, the leave wasn't unlinked, so the time slot stay reserved. Now when a workorder is unlinked, its leave is too. closes odoo/odoo#35003 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
committed by
svs-odoo
parent
2a2c27fa45
commit
275dcfa412
@@ -210,6 +210,7 @@ class MrpWorkorder(models.Model):
|
||||
def unlink(self):
|
||||
# Removes references to workorder to avoid Validation Error
|
||||
(self.mapped('move_raw_ids') | self.mapped('move_finished_ids')).write({'workorder_id': False})
|
||||
self.mapped('leave_id').unlink()
|
||||
return super(MrpWorkorder, self).unlink()
|
||||
|
||||
@api.depends('production_id.product_qty', 'qty_produced')
|
||||
|
||||
@@ -1038,3 +1038,30 @@ class TestWorkOrderProcess(TestMrpCommon):
|
||||
mo.action_confirm()
|
||||
with self.assertRaises(UserError):
|
||||
mo.button_plan()
|
||||
|
||||
def test_plan_unplan_date(self):
|
||||
""" Testing planning a workorder then cancel it and then plan it again.
|
||||
The planned date must be the same the first time and the second time the
|
||||
workorder is planned."""
|
||||
planned_date = datetime(2019, 5, 13, 9, 0)
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.product_id = self.product_4
|
||||
mo_form.bom_id = self.planning_bom
|
||||
mo_form.product_qty = 1
|
||||
mo_form.date_start_wo = planned_date
|
||||
mo = mo_form.save()
|
||||
mo.action_confirm()
|
||||
# Plans the MO and checks the date.
|
||||
mo.button_plan()
|
||||
self.assertAlmostEqual(mo.date_planned_start, planned_date, delta=timedelta(seconds=10))
|
||||
self.assertEqual(bool(mo.workorder_ids.exists()), True)
|
||||
leave = mo.workorder_ids.leave_id
|
||||
self.assertEqual(bool(leave.exists()), True)
|
||||
# Unplans the MO and checks the workorder and its leave no more exist.
|
||||
mo.button_unplan()
|
||||
self.assertEqual(bool(mo.workorder_ids.exists()), False)
|
||||
self.assertEqual(bool(leave.exists()), False)
|
||||
# Plans (again) the MO and checks the date is still the same.
|
||||
mo.button_plan()
|
||||
self.assertAlmostEqual(mo.date_planned_start, planned_date, delta=timedelta(seconds=10))
|
||||
self.assertAlmostEqual(mo.date_planned_start, mo.workorder_ids.date_planned_start, delta=timedelta(seconds=10))
|
||||
|
||||
Reference in New Issue
Block a user