Skip to content
Snippets Groups Projects
Commit d9fa0d15 authored by PNO's avatar PNO
Browse files

[FIX] mrp: compute interval duration with multiple loss_id


When working on an operation in workcenter that requires login, we can add multiple timers.
However, if multiple timers do not have an `end_date` and have different `loss_id`, we will get a traceback (expected singleton) when computing the interval duration.
After this fix, `_convert_to_duration` can be called with multiple productivity loss.

OPW-3292374

closes odoo/odoo#121112

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent c8020619
No related branches found
No related tags found
No related merge requests found
......@@ -359,11 +359,14 @@ class MrpWorkcenterProductivityLoss(models.Model):
and the workcenter has a calendar, convert the dates into a duration based on
working hours.
"""
if (self.loss_type not in ('productive', 'performance')) and workcenter and workcenter.resource_calendar_id:
r = workcenter._get_work_days_data_batch(date_start, date_stop)[workcenter.id]['hours']
return round(r * 60, 2)
else:
return round((date_stop - date_start).total_seconds() / 60.0, 2)
duration = 0
for productivity_loss in self:
if (productivity_loss.loss_type not in ('productive', 'performance')) and workcenter and workcenter.resource_calendar_id:
r = workcenter._get_work_days_data_batch(date_start, date_stop)[workcenter.id]['hours']
duration = max(duration, r * 60)
else:
duration = max(duration, (date_stop - date_start).total_seconds() / 60.0)
return round(duration, 2)
class MrpWorkcenterProductivity(models.Model):
_name = "mrp.workcenter.productivity"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment