mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
updated get_leave_balance_on to consider encashed leaves by default.
This commit is contained in:
@@ -343,7 +343,7 @@ def get_leave_details(employee, date):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
||||||
consider_all_leaves_in_the_allocation_period=False):
|
consider_all_leaves_in_the_allocation_period=False, consider_encshed_leaves=True):
|
||||||
if allocation_records == None:
|
if allocation_records == None:
|
||||||
allocation_records = get_leave_allocation_records(date, employee).get(employee, frappe._dict())
|
allocation_records = get_leave_allocation_records(date, employee).get(employee, frappe._dict())
|
||||||
|
|
||||||
@@ -353,7 +353,10 @@ def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
|||||||
date = allocation.to_date
|
date = allocation.to_date
|
||||||
leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, date, status=Approved)
|
leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, date, status=Approved)
|
||||||
|
|
||||||
return flt(allocation.total_leaves_allocated) - flt(leaves_taken)
|
if frappe.db.get_value("Leave Type", leave_type, 'allow_encashment') and consider_encshed_leaves:
|
||||||
|
leaves_encashed = flt(allocation.total_leaves_encashed)
|
||||||
|
|
||||||
|
return flt(allocation.total_leaves_allocated) - (flt(leaves_taken) + flt(leaves_encashed))
|
||||||
|
|
||||||
def get_leaves_for_period(employee, leave_type, from_date, to_date, status):
|
def get_leaves_for_period(employee, leave_type, from_date, to_date, status):
|
||||||
leave_applications = frappe.db.sql("""
|
leave_applications = frappe.db.sql("""
|
||||||
@@ -391,7 +394,7 @@ def get_leave_allocation_records(date, employee=None):
|
|||||||
conditions = (" and employee='%s'" % employee) if employee else ""
|
conditions = (" and employee='%s'" % employee) if employee else ""
|
||||||
|
|
||||||
leave_allocation_records = frappe.db.sql("""
|
leave_allocation_records = frappe.db.sql("""
|
||||||
select employee, leave_type, total_leaves_allocated, from_date, to_date
|
select employee, leave_type, total_leaves_allocated, total_leaves_encashed, from_date, to_date
|
||||||
from `tabLeave Allocation`
|
from `tabLeave Allocation`
|
||||||
where %s between from_date and to_date and docstatus=1 {0}""".format(conditions), (date), as_dict=1)
|
where %s between from_date and to_date and docstatus=1 {0}""".format(conditions), (date), as_dict=1)
|
||||||
|
|
||||||
@@ -400,7 +403,8 @@ def get_leave_allocation_records(date, employee=None):
|
|||||||
allocated_leaves.setdefault(d.employee, frappe._dict()).setdefault(d.leave_type, frappe._dict({
|
allocated_leaves.setdefault(d.employee, frappe._dict()).setdefault(d.leave_type, frappe._dict({
|
||||||
"from_date": d.from_date,
|
"from_date": d.from_date,
|
||||||
"to_date": d.to_date,
|
"to_date": d.to_date,
|
||||||
"total_leaves_allocated": d.total_leaves_allocated
|
"total_leaves_allocated": d.total_leaves_allocated,
|
||||||
|
"total_leaves_encashed":d.total_leaves_encashed
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return allocated_leaves
|
return allocated_leaves
|
||||||
|
|||||||
Reference in New Issue
Block a user