mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-18 17:15:04 +00:00
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
|
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:
|
if cf_expiry and allocation.unused_leaves:
|
||||||
|
# allocation contains both carry forwarded and new leaves
|
||||||
cf_leaves_taken = get_leaves_for_period(
|
cf_leaves_taken = get_leaves_for_period(
|
||||||
allocation.employee, allocation.leave_type, allocation.from_date, cf_expiry
|
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):
|
if getdate(date) > getdate(cf_expiry):
|
||||||
# carry forwarded leave expiry date passed
|
# carry forwarded leaves have expired
|
||||||
cf_leaves = remaining_cf_leaves = flt(cf_leaves_taken)
|
cf_leaves = remaining_cf_leaves = 0
|
||||||
else:
|
else:
|
||||||
cf_leaves = flt(allocation.unused_leaves) + flt(cf_leaves_taken)
|
cf_leaves = flt(allocation.unused_leaves) + flt(cf_leaves_taken)
|
||||||
remaining_cf_leaves = _get_remaining_leaves(cf_leaves, cf_expiry)
|
remaining_cf_leaves = _get_remaining_leaves(cf_leaves, cf_expiry)
|
||||||
|
|
||||||
leave_balance = flt(allocation.new_leaves_allocated) + flt(cf_leaves)
|
# new leaves allocated - new leaves taken + cf leave balance
|
||||||
leave_balance_for_consumption = flt(allocation.new_leaves_allocated) + flt(remaining_cf_leaves)
|
# 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)
|
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)
|
return frappe._dict(leave_balance=leave_balance, leave_balance_for_consumption=remaining_leaves)
|
||||||
|
|||||||
Reference in New Issue
Block a user