From aafb5cb6f684ca28921d2a6de934a5f6fd4f3162 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 30 May 2019 13:13:14 +0530 Subject: [PATCH] fix: ignore expired non-carry forwarded allocation on calculating leaves taken --- .../hr/doctype/leave_application/leave_application.py | 10 +++++++--- .../leave_application/test_leave_application.py | 1 - erpnext/patches/v12_0/generate_leave_ledger_entries.py | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index b1c666ca83..fd13436d8f 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -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= { diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index f5f4fa55f5..30dcafafc7 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -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", diff --git a/erpnext/patches/v12_0/generate_leave_ledger_entries.py b/erpnext/patches/v12_0/generate_leave_ledger_entries.py index 31cbcc6181..dff749fce7 100644 --- a/erpnext/patches/v12_0/generate_leave_ledger_entries.py +++ b/erpnext/patches/v12_0/generate_leave_ledger_entries.py @@ -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