fix: calculate opening leave balance

This commit is contained in:
Mangesh-Khairnar 2019-08-20 19:18:45 +05:30
parent 6d549b03f1
commit c9b6c9bb61

View File

@ -97,16 +97,15 @@ def get_approvers(department):
def get_total_allocated_leaves(employee, leave_type, from_date, to_date): def get_total_allocated_leaves(employee, leave_type, from_date, to_date):
''' Returns leave allocation between from date and to date ''' ''' Returns leave allocation between from date and to date '''
filters= { leave_allocation_records = frappe.db.get_all('Leave Ledger Entry', filters={
'from_date': ['between', (from_date, to_date)], 'docstatus': 1,
'to_date': ['between', (from_date, to_date)], 'is_expired': 0,
'docstatus': 1, 'leave_type': leave_type,
'is_expired': 0, 'employee': employee,
'leave_type': leave_type, 'transaction_type': 'Leave Allocation'
'employee': employee, }, or_filters={
'transaction_type': 'Leave Allocation' 'from_date': ['between', (from_date, to_date)],
} 'to_date': ['between', (from_date, to_date)]
}, fields=['SUM(leaves) as leaves'])
leave_allocation_records = frappe.db.get_all('Leave Ledger Entry', filters=filters, fields=['SUM(leaves) as leaves'])
return flt(leave_allocation_records[0].get('leaves')) if leave_allocation_records else flt(0) return flt(leave_allocation_records[0].get('leaves')) if leave_allocation_records else flt(0)