fix: get_previous_allocation return value

This commit is contained in:
Rucha Mahabal
2023-11-17 18:24:36 +05:30
parent 9139c14639
commit 6cb8a40339

View File

@@ -297,7 +297,7 @@ class LeaveAllocation(Document):
def get_previous_allocation(from_date, leave_type, employee): def get_previous_allocation(from_date, leave_type, employee):
"""Returns document properties of previous allocation""" """Returns document properties of previous allocation"""
Allocation = frappe.qb.DocType("Leave Allocation") Allocation = frappe.qb.DocType("Leave Allocation")
return ( allocations = (
frappe.qb.from_(Allocation) frappe.qb.from_(Allocation)
.select( .select(
Allocation.name, Allocation.name,
@@ -313,8 +313,11 @@ def get_previous_allocation(from_date, leave_type, employee):
& (Allocation.docstatus == 1) & (Allocation.docstatus == 1)
) )
.orderby(Allocation.to_date, order=frappe.qb.desc) .orderby(Allocation.to_date, order=frappe.qb.desc)
.limit(1)
).run(as_dict=True) ).run(as_dict=True)
return allocations[0] if allocations else None
def get_leave_allocation_for_period( def get_leave_allocation_for_period(
employee, leave_type, from_date, to_date, exclude_allocation=None employee, leave_type, from_date, to_date, exclude_allocation=None