From 4abe02f8fe6a832900374534c3dda605cddfac13 Mon Sep 17 00:00:00 2001 From: MerlinGuillaume Date: Mon, 3 Oct 2022 12:04:53 +0000 Subject: [PATCH] [FIX] mrp: write one of start or end date on workorder When writing a workorder start or end date from its manufacturing order (and if the MO is unplanned), an error is thrown Steps to reproduce: 1. Install Manufacturing 2. Go to Settings > Manufacturing > Operations and enable Work Orders 3. Open an MO with Work Orders 4. Unplan the MO 5. Add a Scheduled End Date to one of the Work Orders 6. Save 7. An error is thrown Solution: Compute the new duration only if both `start_date` and `end_date` are set (and one of `date_planned_start` and `date_planned_finished` is passed in values) Problem: When only one of `date_planned_start` or `date_planned_finished` is written on an `mrp_workorder` (and the other is not set), the method `_calculate_duration_expected` is called but it fails because it passes a False value instead of a datetime which will raise the error `'bool' object has no attribute 'tzinfo'` opw-3004280 closes odoo/odoo#103927 X-original-commit: 35a596dbbc4e2e55461bf7e5e8ae12873249d4af Signed-off-by: William Henrotin (whe) Signed-off-by: Guillaume Merlin (megu) --- addons/mrp/models/mrp_workorder.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index f22a39c9af1..49907a0bb57 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -448,19 +448,16 @@ class MrpWorkorder(models.Model): workorder.leave_id.resource_id = self.env['mrp.workcenter'].browse(values['workcenter_id']).resource_id if 'date_planned_start' in values or 'date_planned_finished' in values: for workorder in self: - start_date = fields.Datetime.to_datetime(values.get('date_planned_start')) or workorder.date_planned_start - end_date = fields.Datetime.to_datetime(values.get('date_planned_finished')) or workorder.date_planned_finished + start_date = fields.Datetime.to_datetime(values.get('date_planned_start', workorder.date_planned_start)) + end_date = fields.Datetime.to_datetime(values.get('date_planned_finished', workorder.date_planned_finished)) if start_date and end_date and start_date > end_date: raise UserError(_('The planned end date of the work order cannot be prior to the planned start date, please correct this to save the work order.')) if 'duration_expected' not in values and not self.env.context.get('bypass_duration_calculation'): if values.get('date_planned_start') and values.get('date_planned_finished'): computed_finished_time = workorder._calculate_date_planned_finished(start_date) values['date_planned_finished'] = computed_finished_time - elif values.get('date_planned_start'): - computed_duration = workorder._calculate_duration_expected(date_planned_start=start_date) - values['duration_expected'] = computed_duration - elif values.get('date_planned_finished'): - computed_duration = workorder._calculate_duration_expected(date_planned_finished=end_date) + elif start_date and end_date: + computed_duration = workorder._calculate_duration_expected(date_planned_start=start_date, date_planned_finished=end_date) values['duration_expected'] = computed_duration # Update MO dates if the start date of the first WO or the # finished date of the last WO is update.