refactor: consider cases for partially consumed cf and new leaves
- the above two cases weren't considering the split between cf leaves taken and new leaves taken and substracting all consumed leaves from cf leaves
This commit is contained in:
@@ -935,25 +935,33 @@ def get_remaining_leaves(
|
||||
|
||||
return remaining_leaves
|
||||
|
||||
leave_balance = leave_balance_for_consumption = flt(allocation.total_leaves_allocated) + flt(
|
||||
leaves_taken
|
||||
)
|
||||
|
||||
# balance for carry forwarded leaves
|
||||
if cf_expiry and allocation.unused_leaves:
|
||||
# allocation contains both carry forwarded and new leaves
|
||||
cf_leaves_taken = get_leaves_for_period(
|
||||
allocation.employee, allocation.leave_type, allocation.from_date, cf_expiry
|
||||
)
|
||||
new_leaves_taken = get_leaves_for_period(
|
||||
allocation.employee, allocation.leave_type, add_days(cf_expiry, 1), allocation.to_date
|
||||
)
|
||||
|
||||
if getdate(date) > getdate(cf_expiry):
|
||||
# carry forwarded leave expiry date passed
|
||||
cf_leaves = remaining_cf_leaves = flt(cf_leaves_taken)
|
||||
# carry forwarded leaves have expired
|
||||
cf_leaves = remaining_cf_leaves = 0
|
||||
else:
|
||||
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)
|
||||
leave_balance_for_consumption = flt(allocation.new_leaves_allocated) + flt(remaining_cf_leaves)
|
||||
# new leaves allocated - new leaves taken + cf leave balance
|
||||
# Note: `new_leaves_taken` is added here because its already a -ve number in the ledger
|
||||
leave_balance = (flt(allocation.new_leaves_allocated) + flt(new_leaves_taken)) + flt(cf_leaves)
|
||||
leave_balance_for_consumption = (
|
||||
flt(allocation.new_leaves_allocated) + flt(new_leaves_taken)
|
||||
) + flt(remaining_cf_leaves)
|
||||
else:
|
||||
# allocation only contains newly allocated leaves
|
||||
leave_balance = leave_balance_for_consumption = flt(allocation.total_leaves_allocated) + flt(
|
||||
leaves_taken
|
||||
)
|
||||
|
||||
remaining_leaves = _get_remaining_leaves(leave_balance_for_consumption, allocation.to_date)
|
||||
return frappe._dict(leave_balance=leave_balance, leave_balance_for_consumption=remaining_leaves)
|
||||
|
||||
Reference in New Issue
Block a user