Skip to content

Commit

Permalink
fix: consider leaves taken within carry-forwarded period separately w…
Browse files Browse the repository at this point in the history
…hile calculating balance
  • Loading branch information
ruchamahabal committed Mar 10, 2023
1 parent e74e02b commit 52108d5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions erpnext/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ def get_leave_allocation_records(employee, date, leave_type=None):
Min(Ledger.from_date).as_("from_date"),
Max(Ledger.to_date).as_("to_date"),
Ledger.leave_type,
Ledger.employee,
)
.where(
(Ledger.from_date <= date)
Expand Down Expand Up @@ -895,6 +896,7 @@ def get_leave_allocation_records(employee, date, leave_type=None):
"unused_leaves": d.cf_leaves,
"new_leaves_allocated": d.new_leaves,
"leave_type": d.leave_type,
"employee": d.employee,
}
),
)
Expand Down Expand Up @@ -939,11 +941,15 @@ def _get_remaining_leaves(remaining_leaves, end_date):

# balance for carry forwarded leaves
if cf_expiry and allocation.unused_leaves:
cf_leaves_taken = get_leaves_for_period(
allocation.employee, allocation.leave_type, allocation.from_date, cf_expiry
)

if getdate(date) > getdate(cf_expiry):
# carry forwarded leave expiry date passed
cf_leaves = remaining_cf_leaves = flt(leaves_taken)
cf_leaves = remaining_cf_leaves = flt(cf_leaves_taken)
else:
cf_leaves = flt(allocation.unused_leaves) + flt(leaves_taken)
cf_leaves = flt(allocation.unused_leaves) + flt(cf_leaves_taken)
remaining_cf_leaves = _get_remaining_leaves(cf_leaves, cf_expiry)

leave_balance = flt(allocation.new_leaves_allocated) + flt(cf_leaves)
Expand Down

0 comments on commit 52108d5

Please sign in to comment.