From ec109b48adb076a809d86b5c2fe4f15277cc8aaa Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Thu, 14 Oct 2021 12:57:11 +0000 Subject: [PATCH] [FIX] mrp_workorder: calculate correctly the WO scheduled end date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - install mrp_workorder - Create a new work center which will work every day from 8:00-9:00 - Create a BOM with component and operation, which takes 24 minutes in your work center - Create 4 MO for this bom - Set manually scheduled date > 1 MO should have a different date than others, e.g: - 3 MO → 01/dec/2021 08:00 - 1 MO → 02/dec/2021 08:00 - Plan the MO which has different date than others The ```planned_end_date``` is not calculated correctly Current behavior before PR: MO_1 : 01/dec/2021 08:00 → 01/dec/2021 08:24 MO_2 : 01/dec/2021 08:24 → 01/dec/2021 08:48 MO_3 : 02/dec/2021 08:00 → 02/dec/2021 08:24 MO_4 : 02/dec/2021 08:24 → 02/dec/2021 08:24 Problem The MO_4 should only last 20 minutes, while it lasts 23 hours and 48 minutes. opw-2648065 closes odoo/odoo#79184 X-original-commit: b02cdbbe36ead262331fc74ec3039c8ded313d3d Related: odoo/enterprise#21992 Signed-off-by: Rémy Voet Signed-off-by: Djamel Touati (otd) --- addons/mrp/models/mrp_workcenter.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/mrp/models/mrp_workcenter.py b/addons/mrp/models/mrp_workcenter.py index 64a2c145495..5d969ce6cde 100644 --- a/addons/mrp/models/mrp_workcenter.py +++ b/addons/mrp/models/mrp_workcenter.py @@ -251,18 +251,21 @@ class MrpWorkcenter(models.Model): available_intervals = get_available_intervals(dt, dt + delta)[resource.id] workorder_intervals = get_workorder_intervals(dt, dt + delta)[resource.id] for start, stop, dummy in available_intervals: - interval_minutes = (stop - start).total_seconds() / 60 - # If the remaining minutes has never decrease update start_interval - if remaining == duration: - start_interval = start - # If there is a overlap between the possible available interval and a others WO - if Intervals([(start_interval, start + timedelta(minutes=min(remaining, interval_minutes)), dummy)]) & workorder_intervals: - remaining = duration - start_interval = start - elif float_compare(interval_minutes, remaining, precision_digits=3) >= 0: - return revert(start_interval), revert(start + timedelta(minutes=remaining)) - # Decrease a part of the remaining duration - remaining -= interval_minutes + # Shouldn't loop more than 2 times because the available_intervals contains the workorder_intervals + # And remaining == duration can only occur at the first loop and at the interval intersection (cannot happen several time because available_intervals > workorder_intervals + for _i in range(2): + interval_minutes = (stop - start).total_seconds() / 60 + # If the remaining minutes has never decrease update start_interval + if remaining == duration: + start_interval = start + # If there is a overlap between the possible available interval and a others WO + if Intervals([(start_interval, start + timedelta(minutes=min(remaining, interval_minutes)), dummy)]) & workorder_intervals: + remaining = duration + elif float_compare(interval_minutes, remaining, precision_digits=3) >= 0: + return revert(start_interval), revert(start + timedelta(minutes=remaining)) + else: + # Decrease a part of the remaining duration + remaining -= interval_minutes return False, 'Not available slot 700 days after the planned start' def action_archive(self):