diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index a445cab7d9f..43ceda875e1 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -297,7 +297,7 @@ class LeaveAllocation(Document): def get_previous_allocation(from_date, leave_type, employee): """Returns document properties of previous allocation""" Allocation = frappe.qb.DocType("Leave Allocation") - return ( + allocations = ( frappe.qb.from_(Allocation) .select( Allocation.name, @@ -313,8 +313,11 @@ def get_previous_allocation(from_date, leave_type, employee): & (Allocation.docstatus == 1) ) .orderby(Allocation.to_date, order=frappe.qb.desc) + .limit(1) ).run(as_dict=True) + return allocations[0] if allocations else None + def get_leave_allocation_for_period( employee, leave_type, from_date, to_date, exclude_allocation=None