Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop leave allocation for left employees #2358

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions hrms/hr/utils.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this exclude employees who left in the middle of the month and who need allocate partial leave to be paid in final settlement?

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
Loading