[FIX] hr_holidays: Fix deleted default employee
The goal of commit 2dbce5e was to handle the company
holiday type in onchange which was probably forgotten
when the company type was introduced.
However because the last `elif` was changed to `else`,
the `else` clause is executed in some situations where
it shouldn't.
e.g. If holiday type is `employee` and an employee is set,
the `else` clause is (obviously wrongly) executed.
This is particularly a problem if the employee is not
HR user nor manager. In that case, the field employee_id
is invisible and its value has been deleted by the onchange.
The allocation cannot be saved because it violates the
sql constraint (employee is null).
Also, the `mode_company_id` and `category_id` should be set
to `False` when the holiday type is not company/category.
This commit is contained in:
committed by
Yannick Tivisse
parent
d6242a340d
commit
08da07b1ca
@@ -244,15 +244,25 @@ class HolidaysAllocation(models.Model):
|
||||
@api.onchange('holiday_type')
|
||||
def _onchange_type(self):
|
||||
if self.holiday_type == 'employee':
|
||||
if not self.employee_id and self.env.user.employee_ids:
|
||||
self.employee_id = self.env.user.employee_ids[0]
|
||||
if not self.employee_id:
|
||||
self.employee_id = self.env.user.employee_ids[:1].id
|
||||
self.mode_company_id = False
|
||||
self.category_id = False
|
||||
elif self.holiday_type == 'company':
|
||||
self.employee_id = False
|
||||
if not self.mode_company_id:
|
||||
self.mode_company_id = self.env.user.company_id.id
|
||||
self.category_id = False
|
||||
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
|
||||
else:
|
||||
self.employee_id = None
|
||||
self.department_id = None
|
||||
self.employee_id = False
|
||||
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
|
||||
elif self.holiday_type == 'category':
|
||||
self.employee_id = False
|
||||
self.mode_company_id = False
|
||||
self.department_id = False
|
||||
|
||||
@api.onchange('employee_id')
|
||||
def _onchange_employee(self):
|
||||
|
||||
@@ -165,3 +165,11 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
leave.action_approve()
|
||||
member_ids = self.hr_dept.member_ids.ids
|
||||
self.assertEqual(self.env['hr.leave'].search_count([('employee_id', 'in', member_ids)]), len(member_ids), "Leave should be created for members of department")
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_allocation_request(self):
|
||||
""" Create an allocation request """
|
||||
# employee should be set to current user
|
||||
allocation_form = Form(self.env['hr.leave.allocation'].sudo(self.user_employee))
|
||||
allocation_form.holiday_status_id = self.holidays_type_1
|
||||
allocation = allocation_form.save()
|
||||
|
||||
Reference in New Issue
Block a user