Skip to content

Commit d72aaba

Browse files
romaincarlier4tivisse
authored andcommitted
[FIX] hr_holidays: fix time off balance on kanban cards
In hr_leave kanban cards, the time off balance for that time off type is shown. The amount were incorrectly computed. This commit fixes the issue by filtering out the expired leave allocations. Done as part of task-4860260 closes odoo#216690 X-original-commit: a49d34b Signed-off-by: Yannick Tivisse (yti) <[email protected]>
1 parent 1a029ae commit d72aaba

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

addons/hr_holidays/models/hr_leave.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,10 @@ def _compute_leaves(self):
659659
for leave in self:
660660
virtual_remaining_leaves = 0
661661
max_leaves = 0
662-
for allocation_dict in employee_days_per_allocation[leave.employee_id][leave.holiday_status_id].values():
663-
max_leaves += allocation_dict['max_leaves']
664-
virtual_remaining_leaves += allocation_dict['virtual_remaining_leaves']
662+
for allocation, allocation_dict in employee_days_per_allocation[leave.employee_id][leave.holiday_status_id].items():
663+
if allocation and (not allocation.date_to or allocation.date_to >= date_from):
664+
max_leaves += allocation_dict['max_leaves']
665+
virtual_remaining_leaves += allocation_dict['virtual_remaining_leaves']
665666
leave.virtual_remaining_leaves = virtual_remaining_leaves
666667
leave.max_leaves = max_leaves
667668

addons/hr_holidays/tests/test_allocations.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,53 @@ def test_create_allocation_from_company_with_no_employee_for_current_user(self):
402402
allocation_form.holiday_status_id = self.leave_type
403403
allocation = allocation_form.save()
404404
self.assertTrue(allocation)
405+
406+
def test_hr_leave_allocation_balance(self):
407+
"""
408+
This test makes sure that the time off balance showed on the time off management kanban card is correct
409+
"""
410+
leave_type = self.env.ref('hr_holidays.leave_type_compensatory_days')
411+
412+
invalid_allocation = self.env['hr.leave.allocation'].sudo().create({
413+
'name': 'Alloc',
414+
'employee_id': self.employee.id,
415+
'holiday_status_id': leave_type.id,
416+
'number_of_days': 5,
417+
'allocation_type': 'regular',
418+
'date_from': date(2024, 1, 1),
419+
'date_to': date(2024, 4, 30)
420+
})
421+
invalid_allocation.action_approve()
422+
423+
first_valid_allocation = self.env['hr.leave.allocation'].sudo().create({
424+
'name': 'Alloc',
425+
'employee_id': self.employee.id,
426+
'holiday_status_id': leave_type.id,
427+
'number_of_days': 10,
428+
'allocation_type': 'regular',
429+
'date_from': date(2024, 1, 1),
430+
'date_to': False
431+
})
432+
first_valid_allocation.action_approve()
433+
434+
second_valid_allocation = self.env['hr.leave.allocation'].sudo().create({
435+
'name': 'Alloc',
436+
'employee_id': self.employee.id,
437+
'holiday_status_id': leave_type.id,
438+
'number_of_days': 12,
439+
'allocation_type': 'regular',
440+
'date_from': date(2025, 1, 1),
441+
'date_to': date.today()
442+
})
443+
second_valid_allocation.action_approve()
444+
445+
leave = self.env['hr.leave'].create({
446+
'employee_id': self.employee.id,
447+
'holiday_status_id': leave_type.id,
448+
'request_date_from': date(2025, 1, 1),
449+
'request_date_to': date(2025, 1, 10)
450+
})
451+
leave._action_validate()
452+
453+
self.assertEqual(leave.max_leaves, 22)
454+
self.assertEqual(leave.virtual_remaining_leaves, 14)

0 commit comments

Comments
 (0)