summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2019-08-09 12:02:05 +0000
committersvs-odoo <svs@odoo.com>2019-08-14 08:44:52 +0000
commit275dcfa41285e03b8ce6611277867101bebc6af3 (patch)
tree250a6962412bf411edeca54a4809b7b258288d32
parent2a2c27fa45d2a9859cf3714dc5c7d66cf0022e33 (diff)
[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>
-rw-r--r--addons/mrp/models/mrp_workorder.py1
-rw-r--r--addons/mrp/tests/test_workorder_operation.py27
2 files changed, 28 insertions, 0 deletions
diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py
index 2fd03cc7654..51085a36747 100644
--- a/addons/mrp/models/mrp_workorder.py
+++ b/addons/mrp/models/mrp_workorder.py
@@ -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')
diff --git a/addons/mrp/tests/test_workorder_operation.py b/addons/mrp/tests/test_workorder_operation.py
index d4a1f84076d..da325320411 100644
--- a/addons/mrp/tests/test_workorder_operation.py
+++ b/addons/mrp/tests/test_workorder_operation.py
@@ -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))