[FIX] ressource: _leave_intervals_batch find public leaves
Issue : - When you check-in/out on a day of time off, all the time is logged as extra hours. - When you do the same on a public holiday, it's not. _leave_intervals_batch is used to get all leave for an employee but the domain for the search only find leaves related to given ressources. Public Holiday Leaves are not related to any specific ressources and thus where never found. closes odoo/odoo#142728 Task-id: 3465686 X-original-commit: 8d7100d08ecabe72dc9aedb036d7908fcd7a35bb Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
This commit is contained in:
@@ -10,4 +10,5 @@ class HrAttendance(models.Model):
|
||||
|
||||
def _get_overtime_leave_domain(self):
|
||||
domain = super()._get_overtime_leave_domain()
|
||||
return AND([domain, [('holiday_id.holiday_status_id.time_type', '=', 'leave')]])
|
||||
# resource_id = False => Public holidays
|
||||
return AND([domain, ['|', ('holiday_id.holiday_status_id.time_type', '=', 'leave'), ('resource_id', '=', False)]])
|
||||
|
||||
@@ -244,3 +244,14 @@ class TestHolidaysOvertime(TransactionCase):
|
||||
.new({'reason': 'Test remove holiday'}) \
|
||||
.action_cancel_leave()
|
||||
self.assertFalse(leave.overtime_id.exists())
|
||||
|
||||
def test_public_leave_overtime(self):
|
||||
self.env['resource.calendar.leaves'].create([{
|
||||
'name': 'Public Holiday',
|
||||
'date_from': datetime(2022, 5, 5, 6),
|
||||
'date_to': datetime(2022, 5, 5, 18),
|
||||
'time_type': 'leave',
|
||||
}])
|
||||
|
||||
self.new_attendance(check_in=datetime(2022, 5, 5, 8), check_out=datetime(2022, 5, 5, 16))
|
||||
self.assertEqual(self.employee.total_overtime, 7, 'Should have 7 hours of overtime (there is one hour of lunch)')
|
||||
|
||||
@@ -384,14 +384,14 @@ class ResourceCalendar(models.Model):
|
||||
resources_list = [resources]
|
||||
else:
|
||||
resources_list = list(resources) + [self.env['resource.resource']]
|
||||
resource_ids = [r.id for r in resources_list]
|
||||
if domain is None:
|
||||
domain = [('time_type', '=', 'leave')]
|
||||
if not any_calendar:
|
||||
domain = domain + [('calendar_id', 'in', [False, self.id])]
|
||||
# for the computation, express all datetimes in UTC
|
||||
# Public leave don't have a resource_id
|
||||
domain = domain + [
|
||||
('resource_id', 'in', resource_ids),
|
||||
('resource_id', 'in', [False] + [r.id for r in resources_list]),
|
||||
('date_from', '<=', datetime_to_string(end_dt)),
|
||||
('date_to', '>=', datetime_to_string(start_dt)),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user