From 6119b7337c79e7152b02b9a470c3131df5062356 Mon Sep 17 00:00:00 2001 From: anoop Date: Fri, 11 May 2018 20:27:10 +0530 Subject: [PATCH] updated get_leave_balance_on to consider encashed leaves by default. --- .../doctype/leave_application/leave_application.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index fad40684f1..b33def2058 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -343,7 +343,7 @@ def get_leave_details(employee, date): @frappe.whitelist() 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: 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 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): 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 "" 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` 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({ "from_date": d.from_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