fix: ignore expired non-carry forwarded allocation on calculating leaves taken

This commit is contained in:
Mangesh-Khairnar 2019-05-30 13:13:14 +05:30
parent ded33a7e2e
commit aafb5cb6f6
3 changed files with 8 additions and 6 deletions

View File

@ -431,7 +431,7 @@ def get_leave_details(employee, date):
return ret
@frappe.whitelist()
def get_leave_balance_on(employee, leave_type, date, to_date=nowdate(), allocation_records=None, docname=None,
def get_leave_balance_on(employee, leave_type, date, to_date=nowdate(), allocation_records=None,
consider_all_leaves_in_the_allocation_period=False):
''' Returns leave balance till date and fetches expiry date based on to_date
to calculate minimum remaining leave balance '''
@ -467,13 +467,17 @@ def get_remaining_leaves(allocation, leaves_taken, date, expiry):
def get_leaves_taken(employee, leave_type, from_date, to_date):
''' Returns leaves taken based on leave application/encashment '''
return frappe.db.get_value("Leave Ledger Entry", filters={
leaves = frappe.db.get_all("Leave Ledger Entry", filters={
'Employee':employee,
'leave_type':leave_type,
'leaves': ("<", 0),
'to_date':("<=", to_date),
'from_date': (">=", from_date)},
fieldname=['SUM(leaves)'])
or_filters={
'is_expired': 0,
'is_carry_forward': 1
}, fields=['SUM(leaves) as leaves'])
return leaves[0]['leaves'] if leaves else None
def get_total_allocated_leaves(employee, leave_type, date):
filters= {

View File

@ -538,7 +538,6 @@ class TestLeaveApplication(unittest.TestCase):
self.assertEquals(leave_ledger_entry[1].leaves, -2)
def create_carry_forwarded_allocation(employee, leave_type):
# initial leave allocation
leave_allocation = create_leave_allocation(
leave_type="_Test_CF_leave_expiry",

View File

@ -104,8 +104,7 @@ def get_leave_encashment_records(allocation_list):
employee,
leave_type,
encashable_days,
from_date,
to_date
encashment_date
FROM `tabLeave Encashment`
WHERE
leave_type = %s