From bc792b225b7871925ea661911e6d8048af651492 Mon Sep 17 00:00:00 2001 From: Hardik Prajapati Date: Fri, 14 Feb 2020 10:15:11 +0000 Subject: [PATCH] [FIX] hr_holidays: Fix access error on leave allocation with multi-company Current Behaviour: As Admin: - Install timeoff and enable Multi company - Create new company and switch to that company - Go to timeoff > Managers > All > Allocations > Create a record An AccessError is raised from `_onchange_type` because it try to access `employee_ids[:1].id` and it may gives employee of another company. Expected Behaviour: After this commit, it will not raise the AccessError. if employee of that company is exist then and then set on leave allocation. so we have already compute field `employee_id`, it will gives employee of current company. closes odoo/odoo#49120 Taskid: 2179571 Closes: #45381 X-original-commit: 73b3d11a0b443116ce91d889397c6d85a13ca1eb Related: odoo/enterprise#9712 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_holidays/models/hr_leave_allocation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index b5c07f5d2ee..60aa7985ad8 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -308,7 +308,7 @@ class HolidaysAllocation(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.user.employee_id.id self.mode_company_id = False self.category_id = False elif self.holiday_type == 'company': @@ -321,7 +321,7 @@ class HolidaysAllocation(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.user.employee_id.department_id.id elif self.holiday_type == 'category': self.employee_id = False self.mode_company_id = False