Skip to content

Commit

Permalink
fix: stop leave allocation for left employees (backport #2358) (#2363)
Browse files Browse the repository at this point in the history
Co-authored-by: Aysha <[email protected]>
  • Loading branch information
mergify[bot] and AyshaHakeem authored Oct 30, 2024
1 parent 6da012d commit eccc11c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ def allocate_earned_leaves():

for e_leave_type in e_leave_types:
leave_allocations = get_leave_allocations(today, e_leave_type.name)

for allocation in leave_allocations:
if not allocation.leave_policy_assignment and not allocation.leave_policy:
continue
Expand Down Expand Up @@ -461,15 +460,29 @@ def round_earned_leaves(earned_leaves, rounding):


def get_leave_allocations(date, leave_type):
return frappe.db.sql(
"""select name, employee, from_date, to_date, leave_policy_assignment, leave_policy
from `tabLeave Allocation`
where
%s between from_date and to_date and docstatus=1
and leave_type=%s""",
(date, leave_type),
as_dict=1,
employee = frappe.qb.DocType("Employee")
leave_allocation = frappe.qb.DocType("Leave Allocation")
query = (
frappe.qb.from_(leave_allocation)
.join(employee)
.on(leave_allocation.employee == employee.name)
.select(
leave_allocation.name,
leave_allocation.employee,
leave_allocation.from_date,
leave_allocation.to_date,
leave_allocation.leave_policy_assignment,
leave_allocation.leave_policy,
)
.where(
(date >= leave_allocation.from_date)
& (date <= leave_allocation.to_date)
& (leave_allocation.docstatus == 1)
& (leave_allocation.leave_type == leave_type)
& (employee.status != "Left")
)
)
return query.run(as_dict=1) or []


def get_earned_leaves():
Expand Down

0 comments on commit eccc11c

Please sign in to comment.