Skip to content

Commit

Permalink
test(Comp Leave): correct allocation update in case of multiple alloc…
Browse files Browse the repository at this point in the history
…ations in leave periods

(cherry picked from commit f20c15b)

# Conflicts:
#	hrms/hr/doctype/compensatory_leave_request/test_compensatory_leave_request.py
  • Loading branch information
ruchamahabal authored and mergify[bot] committed Jan 10, 2025
1 parent 19304f4 commit 07bce3a
Showing 1 changed file with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@

import frappe
from frappe.tests.utils import FrappeTestCase
<<<<<<< HEAD
from frappe.utils import add_days, add_months, today
=======
from frappe.utils import add_days, add_months, getdate, today
>>>>>>> f20c15bb (test(Comp Leave): correct allocation update in case of multiple allocations in leave periods)

from hrms.hr.doctype.attendance_request.test_attendance_request import get_employee
from hrms.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation
from hrms.hr.doctype.leave_application.leave_application import get_leave_balance_on
from hrms.hr.doctype.leave_period.test_leave_period import create_leave_period
from hrms.tests.test_utils import add_date_to_holiday_list

test_dependencies = ["Employee"]

<<<<<<< HEAD

=======
>>>>>>> f20c15bb (test(Comp Leave): correct allocation update in case of multiple allocations in leave periods)
class TestCompensatoryLeaveRequest(FrappeTestCase):
def setUp(self):
frappe.db.delete("Compensatory Leave Request")
Expand Down Expand Up @@ -42,7 +49,7 @@ def test_leave_balance_on_submit(self):
before + 1,
)

def test_leave_allocation_update_on_submit(self):
def test_allocation_update_on_submit(self):
employee = get_employee()
mark_attendance(employee, date=add_days(today(), -1))
compensatory_leave_request = get_compensatory_leave_request(
Expand Down Expand Up @@ -70,6 +77,54 @@ def test_leave_allocation_update_on_submit(self):
)
self.assertEqual(leaves_allocated, 2)

def test_allocation_update_on_submit_on_multiple_allocations(self):
"""Tests whether the correct allocation is updated when there are multiple allocations in the same leave period"""
employee = get_employee()
today = getdate()

first_alloc_start = add_months(today, -3)
first_alloc_end = add_days(today, -1)
second_alloc_start = today
second_alloc_end = add_months(today, 1)

add_date_to_holiday_list(first_alloc_start, employee.holiday_list)
allocation_1 = create_leave_allocation(
leave_type="Compensatory Off",
employee=employee.name,
from_date=first_alloc_start,
to_date=first_alloc_end,
)
allocation_1.new_leaves_allocated = 0
allocation_1.submit()

add_date_to_holiday_list(second_alloc_start, employee.holiday_list)
allocation_2 = create_leave_allocation(
leave_type="Compensatory Off",
employee=employee.name,
from_date=second_alloc_start,
to_date=second_alloc_end,
)
allocation_2.new_leaves_allocated = 0
allocation_2.submit()

# adds leave balance in first allocation
mark_attendance(employee, date=first_alloc_start)
compensatory_leave_request = get_compensatory_leave_request(
employee.name, leave_date=first_alloc_start
)
compensatory_leave_request.submit()
allocation_1.reload()
self.assertEqual(allocation_1.total_leaves_allocated, 1)

# adds leave balance in second allocation
mark_attendance(employee, date=second_alloc_start)
compensatory_leave_request = get_compensatory_leave_request(
employee.name, leave_date=second_alloc_start
)
compensatory_leave_request.submit()
allocation_2.reload()
self.assertEqual(allocation_2.total_leaves_allocated, 1)

def test_creation_of_leave_ledger_entry_on_submit(self):
"""check creation of leave ledger entry on submission of leave request"""
employee = get_employee()
Expand Down

0 comments on commit 07bce3a

Please sign in to comment.