[FIX] hr_holidays: prevent crash when no employee is linked to the user

This commit is contained in:
Richard Mathot
2017-12-11 13:49:36 +01:00
parent 1f563b713d
commit 6cc5ebed1a
+4 -2
View File
@@ -270,10 +270,12 @@ class Holidays(models.Model):
@api.onchange('holiday_type')
def _onchange_type(self):
if self.holiday_type == 'employee' and not self.employee_id:
self.employee_id = self.env.user.employee_ids[0]
if self.env.user.employee_ids:
self.employee_id = self.env.user.employee_ids[0]
elif self.holiday_type == 'department':
if self.env.user.employee_ids:
self.department_id = self.department_id or self.env.user.employee_ids[0].department_id
self.employee_id = None
self.department_id = self.department_id or self.env.user.employee_ids[0].department_id
elif self.holiday_type == 'category':
self.employee_id = None
self.department_id = None