diff options
| -rw-r--r-- | addons/hr_holidays/models/hr_leave.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 356d912c87d..8d12097cdd9 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -307,7 +307,12 @@ class HolidaysRequest(models.Model): @api.depends('holiday_status_id') def _compute_state(self): for holiday in self: - holiday.state = 'confirm' if holiday.validation_type != 'no_validation' else 'draft' + if self.env.context.get('unlink') and holiday.state == 'draft': + # Otherwise the record in draft with validation_type in (hr, manager, both) will be set to confirm + # and a simple internal user will not be able to delete his own draft record + holiday.state = 'draft' + else: + holiday.state = 'confirm' if holiday.validation_type != 'no_validation' else 'draft' @api.depends('request_date_from_period', 'request_hour_from', 'request_hour_to', 'request_date_from', 'request_date_to', 'request_unit_half', 'request_unit_hours', 'request_unit_custom', 'employee_id') @@ -822,7 +827,7 @@ class HolidaysRequest(models.Model): else: for holiday in self.filtered(lambda holiday: holiday.state not in ['draft', 'cancel', 'confirm']): raise UserError(error_message % (state_description_values.get(holiday.state),)) - return super(HolidaysRequest, self.with_context(leave_skip_date_check=True)).unlink() + return super(HolidaysRequest, self.with_context(leave_skip_date_check=True, unlink=True)).unlink() def copy_data(self, default=None): if default and 'date_from' in default and 'date_to' in default: |
