Skip to content
Permalink
Browse files

[IMP] mrp: WO do not allow end date < start date

It does not make sense to finish something before starting it.
Do not allow to write on a done WO except for time log.

Related to task 1838642
Closes #25103
  • Loading branch information...
kic-odoo authored and nim-odoo committed May 18, 2018
1 parent 04f7c65 commit aafa0490cb540f1646e1d81c6cdb0cfd4a8b2429
Showing with 7 additions and 1 deletion.
  1. +7 −1 addons/mrp/models/mrp_workorder.py
@@ -240,8 +240,14 @@ def _onchange_qty_producing(self):

@api.multi
def write(self, values):
if ('date_planned_start' in values or 'date_planned_finished' in values) and any(workorder.state == 'done' for workorder in self):
if list(values.keys()) != ['time_ids'] and any(workorder.state == 'done' for workorder in self):
raise UserError(_('You can not change the finished work order.'))
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
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.'))
return super(MrpWorkorder, self).write(values)

def _generate_lot_ids(self):

0 comments on commit aafa049

Please sign in to comment.
You can’t perform that action at this time.