summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Lefèvre <lul@odoo.com>2019-06-19 12:47:05 +0000
committerLucas Lefèvre <lul@odoo.com>2019-06-19 12:53:42 +0000
commit7cbea1dcff16d9f86ac5394ad626d3bd61d6ead2 (patch)
tree088fa31a6bfbca9b56b5bb2e60b169048d2c685f
parente6bfad41f271249fb868238a6f05bbce14fe13f4 (diff)
[FIX] hr_holidays: Don't set all employees absent
When computing `is_absent` for multiple employees (multiple records in `self`), if one employee is really absent (leave), all employee in the recordset are also considered absent. Note: it never happens in saas-12.2 but in master and possibly custo. closes odoo/odoo#34241 Signed-off-by: Romain Libert (rli) <rli@odoo.com>
-rw-r--r--addons/hr_holidays/models/hr.py2
-rw-r--r--addons/hr_holidays/tests/test_leave_requests.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/addons/hr_holidays/models/hr.py b/addons/hr_holidays/models/hr.py
index 2a8a5506217..be5294d847a 100644
--- a/addons/hr_holidays/models/hr.py
+++ b/addons/hr_holidays/models/hr.py
@@ -168,7 +168,7 @@ class Employee(models.Model):
employee.leave_date_to = leave_data.get(employee.id, {}).get('leave_date_to')
employee.current_leave_state = leave_data.get(employee.id, {}).get('current_leave_state')
employee.current_leave_id = leave_data.get(employee.id, {}).get('current_leave_id')
- employee.is_absent = leave_data and leave_data.get(employee.id, {}).get('current_leave_state') not in ['cancel', 'refuse', 'draft']
+ employee.is_absent = leave_data.get(employee.id) and leave_data.get(employee.id, {}).get('current_leave_state') not in ['cancel', 'refuse', 'draft']
@api.onchange('parent_id')
def _onchange_parent_id(self):
diff --git a/addons/hr_holidays/tests/test_leave_requests.py b/addons/hr_holidays/tests/test_leave_requests.py
index f15f9cfb9e5..47b0af4f292 100644
--- a/addons/hr_holidays/tests/test_leave_requests.py
+++ b/addons/hr_holidays/tests/test_leave_requests.py
@@ -173,3 +173,18 @@ class TestLeaveRequests(TestHrHolidaysBase):
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()
+
+ @mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
+ def test_employee_is_absent(self):
+ """ Only the concerned employee should be considered absent """
+ self.env['hr.leave'].sudo(self.user_employee_id).create({
+ 'name': 'Hol11',
+ 'employee_id': self.employee_emp_id,
+ 'holiday_status_id': self.holidays_type_1.id,
+ 'date_from': (fields.Datetime.now() - relativedelta(days=1)),
+ 'date_to': fields.Datetime.now() + relativedelta(days=1),
+ 'number_of_days': 2,
+ })
+ (self.employee_emp | self.employee_hrmanager).mapped('is_absent') # compute in batch
+ self.assertTrue(self.employee_emp.is_absent, "He should be considered absent")
+ self.assertFalse(self.employee_hrmanager.is_absent, "He should not be considered absent")