fix: earned leave exceeding annual allocation
This commit is contained in:
@@ -496,18 +496,28 @@ def allocate_earned_leaves():
|
||||
|
||||
|
||||
def update_previous_leave_allocation(allocation, annual_allocation, e_leave_type):
|
||||
allocation = frappe.get_doc("Leave Allocation", allocation.name)
|
||||
annual_allocation = flt(annual_allocation, allocation.precision("total_leaves_allocated"))
|
||||
|
||||
earned_leaves = get_monthly_earned_leave(
|
||||
annual_allocation, e_leave_type.earned_leave_frequency, e_leave_type.rounding
|
||||
)
|
||||
|
||||
allocation = frappe.get_doc("Leave Allocation", allocation.name)
|
||||
new_allocation = flt(allocation.total_leaves_allocated) + flt(earned_leaves)
|
||||
new_allocation_without_cf = flt(
|
||||
flt(allocation.get_existing_leave_count()) + flt(earned_leaves),
|
||||
allocation.precision("total_leaves_allocated"),
|
||||
)
|
||||
|
||||
if new_allocation > e_leave_type.max_leaves_allowed and e_leave_type.max_leaves_allowed > 0:
|
||||
new_allocation = e_leave_type.max_leaves_allowed
|
||||
|
||||
if new_allocation != allocation.total_leaves_allocated:
|
||||
today_date = today()
|
||||
if (
|
||||
new_allocation != allocation.total_leaves_allocated
|
||||
# annual allocation as per policy should not be exceeded
|
||||
and new_allocation_without_cf <= annual_allocation
|
||||
):
|
||||
today_date = frappe.flags.current_date or getdate()
|
||||
|
||||
allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
|
||||
create_additional_leave_ledger_entry(allocation, earned_leaves, today_date)
|
||||
|
||||
Reference in New Issue
Block a user