[FIX] mrp: Fail to set workorder on calendar 'Planning by Workcenter'

Steps to reproduce:
1- Install Manufacturing module
2- Create 2 or more new WOs and make sure that their corresponding MOs is not planned
3- Go to Operations > Work orders
4- Mark all of those WOs and write a start date to apply on all of them
5- Check Planning > Planning by Workcenter 'you will not find the scheduled WOs'

Current behavior before PR:
When you try to mark more than one record in Work orders and set start date for all of them at the same time it will not be set therefore it will not be visible in Planning calendar. This is happening because if you are setting the start date for the first time it will call the function that sets the start date first before calculating the finish date so it will not pass the condition where it checks if both dates have values.

Desired behavior after PR is merged:
Now we are checking just the start date if it has value or not and to raise the same user error if the customer tries to delete the finish date we are checking this on change of the finish date from a value to null.

opw-3596100

closes odoo/odoo#151272

X-original-commit: 70394e616e5d75ee33ed048dbd7210c1926c63be
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Youssef Bashandy (yoba) <yoba@odoo.com>
This commit is contained in:
Youssef Bashandy
2024-01-26 21:07:59 +00:00
parent e796f13d2a
commit 55a4ac8dea
2 changed files with 41 additions and 1 deletions
+5 -1
View File
@@ -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(
+36
View File
@@ -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))