diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index 036fa5068..8dfc006c9 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -88,6 +88,14 @@ class HrLeave(models.Model): for holiday in self.filtered(lambda holiday: holiday.state not in ['draft', 'cancel', 'confirm']): raise UserError(error_message % (state_description_values.get(holiday.state),)) + @api.model + def write(self, vals): + if not self.env.context.get('leave_skip_state_check'): + self = self.with_context(leave_skip_state_check=True) + if 'state' not in vals and self.filtered(lambda r: r.state != 'draft'): + vals['state'] = 'draft' + return super(HrLeave, self).write(vals) + def action_leave_wizard(self): return { "type": "ir.actions.act_window",