[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) <whe@odoo.com>
Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
MerlinGuillaume
2022-10-24 15:12:50 +02:00
parent 178f8666cf
commit 4abe02f8fe
+4 -7
View File
@@ -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.