Show opening balance of leaves (#14925)
* Show opening balance of leaves
* Update employee_leave_balance.py
diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
index 8105e1a..c2191e0 100644
--- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
+++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
@@ -24,6 +24,7 @@
]
for leave_type in leave_types:
+ columns.append(_(leave_type) + " " + _("Opening") + ":Float:160")
columns.append(_(leave_type) + " " + _("Taken") + ":Float:160")
columns.append(_(leave_type) + " " + _("Balance") + ":Float:160")
@@ -32,6 +33,7 @@
def get_data(filters, leave_types):
user = frappe.session.user
allocation_records_based_on_to_date = get_leave_allocation_records(filters.to_date)
+ allocation_records_based_on_from_date = get_leave_allocation_records(filters.from_date)
active_employees = frappe.get_all("Employee",
filters = { "status": "Active", "company": filters.company},
@@ -48,13 +50,17 @@
# leaves taken
leaves_taken = get_approved_leaves_for_period(employee.name, leave_type,
filters.from_date, filters.to_date)
-
+
+ # opening balance
+ opening = get_leave_balance_on(employee.name, leave_type, filters.from_date,
+ allocation_records_based_on_from_date.get(employee.name, frappe._dict()))
+
# closing balance
closing = get_leave_balance_on(employee.name, leave_type, filters.to_date,
allocation_records_based_on_to_date.get(employee.name, frappe._dict()))
- row += [leaves_taken, closing]
+ row += [opening, leaves_taken, closing]
data.append(row)
- return data
\ No newline at end of file
+ return data