|
3 | 3 |
|
4 | 4 | import frappe
|
5 | 5 | from frappe.tests.utils import FrappeTestCase
|
6 |
| -from frappe.utils import add_days, add_months, today |
| 6 | +from frappe.utils import add_days, add_months, getdate, today |
7 | 7 |
|
8 | 8 | from hrms.hr.doctype.attendance_request.test_attendance_request import get_employee
|
| 9 | +from hrms.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation |
9 | 10 | from hrms.hr.doctype.leave_application.leave_application import get_leave_balance_on
|
10 | 11 | from hrms.hr.doctype.leave_period.test_leave_period import create_leave_period
|
11 | 12 | from hrms.tests.test_utils import add_date_to_holiday_list
|
12 | 13 |
|
13 |
| -test_dependencies = ["Employee"] |
14 |
| - |
15 | 14 |
|
16 | 15 | class TestCompensatoryLeaveRequest(FrappeTestCase):
|
17 | 16 | def setUp(self):
|
@@ -42,7 +41,7 @@ def test_leave_balance_on_submit(self):
|
42 | 41 | before + 1,
|
43 | 42 | )
|
44 | 43 |
|
45 |
| - def test_leave_allocation_update_on_submit(self): |
| 44 | + def test_allocation_update_on_submit(self): |
46 | 45 | employee = get_employee()
|
47 | 46 | mark_attendance(employee, date=add_days(today(), -1))
|
48 | 47 | compensatory_leave_request = get_compensatory_leave_request(
|
@@ -70,6 +69,54 @@ def test_leave_allocation_update_on_submit(self):
|
70 | 69 | )
|
71 | 70 | self.assertEqual(leaves_allocated, 2)
|
72 | 71 |
|
| 72 | + def test_allocation_update_on_submit_on_multiple_allocations(self): |
| 73 | + """Tests whether the correct allocation is updated when there are multiple allocations in the same leave period""" |
| 74 | + employee = get_employee() |
| 75 | + today = getdate() |
| 76 | + |
| 77 | + first_alloc_start = add_months(today, -3) |
| 78 | + first_alloc_end = add_days(today, -1) |
| 79 | + second_alloc_start = today |
| 80 | + second_alloc_end = add_months(today, 1) |
| 81 | + |
| 82 | + add_date_to_holiday_list(first_alloc_start, employee.holiday_list) |
| 83 | + allocation_1 = create_leave_allocation( |
| 84 | + leave_type="Compensatory Off", |
| 85 | + employee=employee.name, |
| 86 | + from_date=first_alloc_start, |
| 87 | + to_date=first_alloc_end, |
| 88 | + ) |
| 89 | + allocation_1.new_leaves_allocated = 0 |
| 90 | + allocation_1.submit() |
| 91 | + |
| 92 | + add_date_to_holiday_list(second_alloc_start, employee.holiday_list) |
| 93 | + allocation_2 = create_leave_allocation( |
| 94 | + leave_type="Compensatory Off", |
| 95 | + employee=employee.name, |
| 96 | + from_date=second_alloc_start, |
| 97 | + to_date=second_alloc_end, |
| 98 | + ) |
| 99 | + allocation_2.new_leaves_allocated = 0 |
| 100 | + allocation_2.submit() |
| 101 | + |
| 102 | + # adds leave balance in first allocation |
| 103 | + mark_attendance(employee, date=first_alloc_start) |
| 104 | + compensatory_leave_request = get_compensatory_leave_request( |
| 105 | + employee.name, leave_date=first_alloc_start |
| 106 | + ) |
| 107 | + compensatory_leave_request.submit() |
| 108 | + allocation_1.reload() |
| 109 | + self.assertEqual(allocation_1.total_leaves_allocated, 1) |
| 110 | + |
| 111 | + # adds leave balance in second allocation |
| 112 | + mark_attendance(employee, date=second_alloc_start) |
| 113 | + compensatory_leave_request = get_compensatory_leave_request( |
| 114 | + employee.name, leave_date=second_alloc_start |
| 115 | + ) |
| 116 | + compensatory_leave_request.submit() |
| 117 | + allocation_2.reload() |
| 118 | + self.assertEqual(allocation_2.total_leaves_allocated, 1) |
| 119 | + |
73 | 120 | def test_creation_of_leave_ledger_entry_on_submit(self):
|
74 | 121 | """check creation of leave ledger entry on submission of leave request"""
|
75 | 122 | employee = get_employee()
|
|
0 commit comments