[FIX] hr_holidays: fix multi company issue in onchange

If you are logged into a company that differs from the company of your
employee, you won't be able to read the informations on that employee,
and you will have a crash.
Instead of taking the employee linked to the current user, we use search
in order to first apply the ir.rules hence we ensure that we will be
able to read the needed informations.
This commit is contained in:
RomainLibert
2019-06-05 11:14:55 +00:00
parent 691b0e7e6f
commit c081ee0462
+2 -2
View File
@@ -340,7 +340,7 @@ class HolidaysRequest(models.Model):
def _onchange_type(self):
if self.holiday_type == 'employee':
if not self.employee_id:
self.employee_id = self.env.user.employee_ids[:1].id
self.employee_id = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1).id
self.mode_company_id = False
self.category_id = False
elif self.holiday_type == 'company':
@@ -353,7 +353,7 @@ class HolidaysRequest(models.Model):
self.mode_company_id = False
self.category_id = False
if not self.department_id:
self.department_id = self.env.user.employee_ids[:1].department_id.id
self.department_id = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1).department_id.id
elif self.holiday_type == 'category':
self.employee_id = False
self.mode_company_id = False