diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index ec8756d543f..5c93e0d14fa 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -248,7 +248,8 @@ class MrpWorkorder(models.Model): 'date_from': wo.date_start, 'date_to': wo.date_finished, }) - elif wo.date_start and wo.date_finished: + elif wo.date_start: + wo.date_finished = wo._calculate_date_finished() wo.leave_id = wo.env['resource.calendar.leaves'].create({ 'name': wo.display_name, 'calendar_id': wo.workcenter_id.resource_calendar_id.id, @@ -407,6 +408,9 @@ class MrpWorkorder(models.Model): def _onchange_date_finished(self): if self.date_start and self.date_finished and self.workcenter_id: self.duration_expected = self._calculate_duration_expected() + if not self.date_finished and self.date_start: + raise UserError(_("It is not possible to unplan one single Work Order. " + "You should unplan the Manufacturing Order instead in order to unplan all the linked operations.")) def _calculate_duration_expected(self, date_start=False, date_finished=False): interval = self.workcenter_id.resource_calendar_id.get_work_duration_data( diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 7967b98dcee..f270cf746d3 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -3841,3 +3841,39 @@ class TestMrpOrder(TestMrpCommon): production.button_mark_done() self.assertEqual(production.workorder_ids.duration_expected, init_duration_expected + 5) + + def test_multi_edit_start_date_wo(self): + """ + Test setting the start date for multiple workorders, checking if the finish date + will be set too. As if the finish date is not set the planned workorder will not + be shown in planning gantt view + """ + mo = self.env['mrp.production'].create({ + 'product_id': self.product.id, + 'product_uom_id': self.bom_1.product_uom_id.id, + }) + + wos = self.env['mrp.workorder'].create([ + { + 'name': 'Test order', + 'workcenter_id': self.workcenter_1.id, + 'product_uom_id': self.bom_1.product_uom_id.id, + 'production_id': mo.id, + 'duration_expected': 1.0 + }, + { + 'name': 'Test order2', + 'workcenter_id': self.workcenter_2.id, + 'product_uom_id': self.bom_1.product_uom_id.id, + 'production_id': mo.id, + 'duration_expected': 2.0 + } + ]) + dt = datetime(2024, 1, 17, 11) + wos.date_start = dt + + self.assertEqual(wos[0].date_start, dt) + self.assertEqual(wos[1].date_start, dt) + + self.assertEqual(wos[0].date_finished, dt + timedelta(hours=1, minutes=1)) + self.assertEqual(wos[1].date_finished, dt + timedelta(hours=1, minutes=2))