From df7a13f85347ed9eeac35bc09b304c4fa3deb19b Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Wed, 19 Aug 2020 14:40:31 +0000 Subject: [PATCH] [FIX] mrp: use working calendar when editing wo planned dates - Go to Manufacturing > Configuration and activate Work Orders - Create a Product (i.e. Product X) and create a Bill of Materials for it (with a Routing) - Go to Manufacturing > Operations > Manufacturing Orders and create one for Product X - Mark as Todo and Plan - Go to Manufacturing > Operations > Work Orders and open the created one - In Time Tracking tab, edit Planned Start Date or Expected Duration The Planned End Date is computed without using the working calendar of the work center. The working calendar should be used as it was at creation. opw-2314555 closes odoo/odoo#56290 X-original-commit: 7b70da788d3a222467d88b06324a41e6c6efe605 Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: Anh Thao PHAM --- addons/mrp/models/mrp_workorder.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 3f1d8461381..d5f7ccdcaab 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -351,8 +351,11 @@ class MrpWorkorder(models.Model): @api.onchange('date_planned_finished') def _onchange_date_planned_finished(self): if self.date_planned_start and self.date_planned_finished: - diff = self.date_planned_finished - self.date_planned_start - self.duration_expected = diff.total_seconds() / 60 + interval = self.workcenter_id.resource_calendar_id.get_work_duration_data( + self.date_planned_start, self.date_planned_finished, + domain=[('time_type', 'in', ['leave', 'other'])] + ) + self.duration_expected = interval['hours'] * 60 @api.onchange('operation_id') def _onchange_operation_id(self): @@ -363,7 +366,10 @@ class MrpWorkorder(models.Model): @api.onchange('date_planned_start', 'duration_expected') def _onchange_date_planned_start(self): if self.date_planned_start and self.duration_expected: - self.date_planned_finished = self.date_planned_start + relativedelta(minutes=self.duration_expected) + self.date_planned_finished = self.workcenter_id.resource_calendar_id.plan_hours( + self.duration_expected / 60.0, self.date_planned_start, + compute_leaves=True, domain=[('time_type', 'in', ['leave', 'other'])] + ) @api.onchange('operation_id', 'workcenter_id', 'qty_production') def _onchange_expected_duration(self):