fix: ignore expired non-carry forwarded allocation on calculating leaves taken
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index b1c666c..fd13436 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -431,7 +431,7 @@
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_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 f5f4fa5..30dcafa 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 @@
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 31cbcc6..dff749f 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 @@
employee,
leave_type,
encashable_days,
- from_date,
- to_date
+ encashment_date
FROM `tabLeave Encashment`
WHERE
leave_type = %s