fix: ignore remaining leaves calculation for cf leaves after expiry

- calculate correct cf expiry in the entire allocation period
This commit is contained in:
Rucha Mahabal
2023-02-21 17:12:21 +05:30
parent aea9d82672
commit d82ba4e86f
2 changed files with 10 additions and 5 deletions

View File

@@ -817,7 +817,9 @@ def get_leave_balance_on(
allocation = allocation_records.get(leave_type, frappe._dict()) allocation = allocation_records.get(leave_type, frappe._dict())
end_date = allocation.to_date if cint(consider_all_leaves_in_the_allocation_period) else date end_date = allocation.to_date if cint(consider_all_leaves_in_the_allocation_period) else date
cf_expiry = get_allocation_expiry_for_cf_leaves(employee, leave_type, to_date, date) cf_expiry = get_allocation_expiry_for_cf_leaves(
employee, leave_type, to_date, allocation.from_date
)
leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, end_date) leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, end_date)
@@ -937,6 +939,10 @@ def get_remaining_leaves(
# balance for carry forwarded leaves # balance for carry forwarded leaves
if cf_expiry and allocation.unused_leaves: if cf_expiry and allocation.unused_leaves:
if getdate(date) > getdate(cf_expiry):
# carry forwarded leave expiry date passed
cf_leaves = remaining_cf_leaves = 0
else:
cf_leaves = flt(allocation.unused_leaves) + flt(leaves_taken) cf_leaves = flt(allocation.unused_leaves) + flt(leaves_taken)
remaining_cf_leaves = _get_remaining_leaves(cf_leaves, cf_expiry) remaining_cf_leaves = _get_remaining_leaves(cf_leaves, cf_expiry)

View File

@@ -698,8 +698,7 @@ class TestLeaveApplication(unittest.TestCase):
leave_type_name="_Test_CF_leave_expiry", leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1, is_carry_forward=1,
expire_carry_forwarded_leaves_after_days=90, expire_carry_forwarded_leaves_after_days=90,
) ).insert()
leave_type.insert()
create_carry_forwarded_allocation(employee, leave_type) create_carry_forwarded_allocation(employee, leave_type)
details = get_leave_balance_on( details = get_leave_balance_on(