[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) <nle@odoo.com>
Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
This commit is contained in:
Anh Thao Pham (pta)
2020-08-21 11:39:18 +00:00
parent a5b5b88255
commit df7a13f853
+9 -3
View File
@@ -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):