From 6cb8a403392b52e09d901f5b4d10b63e2b61d2f7 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 17 Nov 2023 18:24:36 +0530 Subject: [PATCH] fix: `get_previous_allocation` return value --- erpnext/hr/doctype/leave_allocation/leave_allocation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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