From c081ee046249f67c10484fddb296a8529f5aa665 Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Wed, 5 Jun 2019 10:00:12 +0000 Subject: [PATCH] [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. --- addons/hr_holidays/models/hr_leave.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index d727b98de7d..8a91c61707c 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -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