fix: leave application dashboard

- total leaves allocated considering cancelled leaves

- optional plural for leave category labels

- show dashboard only once from date is set, else it fetches all allocations till date and generates incorrect balance

- change pending leaves to 'Leaves Pending Approval' for better context

- update labels in Salary Slip Leave Details table
This commit is contained in:
Rucha Mahabal 2022-02-28 14:10:23 +05:30
parent 88141d6116
commit 942511cfff
5 changed files with 20 additions and 17 deletions

View File

@ -52,7 +52,7 @@ frappe.ui.form.on("Leave Application", {
make_dashboard: function(frm) {
var leave_details;
let lwps;
if (frm.doc.employee) {
if (frm.doc.employee && frm.doc.from_date) {
frappe.call({
method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_details",
async: false,
@ -146,6 +146,7 @@ frappe.ui.form.on("Leave Application", {
},
to_date: function(frm) {
frm.trigger("make_dashboard");
frm.trigger("half_day_datepicker");
frm.trigger("calculate_total_days");
},

View File

@ -521,6 +521,7 @@ def get_leave_details(employee, date):
'to_date': ('>=', date),
'employee': employee,
'leave_type': allocation.leave_type,
'docstatus': 1
}, 'SUM(total_leaves_allocated)') or 0
remaining_leaves = get_leave_balance_on(employee, d, date, to_date = allocation.to_date,
@ -528,13 +529,13 @@ def get_leave_details(employee, date):
end_date = allocation.to_date
leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, end_date) * -1
leaves_pending = get_pending_leaves_for_period(employee, d, allocation.from_date, end_date)
leaves_pending = get_leaves_pending_approval_for_period(employee, d, allocation.from_date, end_date)
leave_allocation[d] = {
"total_leaves": total_allocated_leaves,
"expired_leaves": total_allocated_leaves - (remaining_leaves + leaves_taken),
"leaves_taken": leaves_taken,
"pending_leaves": leaves_pending,
"leaves_pending_approval": leaves_pending,
"remaining_leaves": remaining_leaves}
#is used in set query
@ -621,7 +622,7 @@ def get_leave_allocation_records(employee, date, leave_type=None):
}))
return allocated_leaves
def get_pending_leaves_for_period(employee, leave_type, from_date, to_date):
def get_leaves_pending_approval_for_period(employee, leave_type, from_date, to_date):
''' Returns leaves that are pending approval '''
leaves = frappe.get_all("Leave Application",
filters={

View File

@ -4,11 +4,11 @@
<thead>
<tr>
<th style="width: 16%">{{ __("Leave Type") }}</th>
<th style="width: 16%" class="text-right">{{ __("Total Allocated Leave") }}</th>
<th style="width: 16%" class="text-right">{{ __("Expired Leave") }}</th>
<th style="width: 16%" class="text-right">{{ __("Used Leave") }}</th>
<th style="width: 16%" class="text-right">{{ __("Pending Leave") }}</th>
<th style="width: 16%" class="text-right">{{ __("Available Leave") }}</th>
<th style="width: 16%" class="text-right">{{ __("Total Allocated Leave(s)") }}</th>
<th style="width: 16%" class="text-right">{{ __("Expired Leave(s)") }}</th>
<th style="width: 16%" class="text-right">{{ __("Used Leave(s)") }}</th>
<th style="width: 16%" class="text-right">{{ __("Leave(s) Pending Approval") }}</th>
<th style="width: 16%" class="text-right">{{ __("Available Leave(s)") }}</th>
</tr>
</thead>
<tbody>
@ -18,7 +18,7 @@
<td class="text-right"> {%= value["total_leaves"] %} </td>
<td class="text-right"> {%= value["expired_leaves"] %} </td>
<td class="text-right"> {%= value["leaves_taken"] %} </td>
<td class="text-right"> {%= value["pending_leaves"] %} </td>
<td class="text-right"> {%= value["leaves_pending_approval"] %} </td>
<td class="text-right"> {%= value["remaining_leaves"] %} </td>
</tr>
{% } %}

View File

@ -1362,7 +1362,7 @@ class SalarySlip(TransactionBase):
'total_allocated_leaves': flt(leave_values.get('total_leaves')),
'expired_leaves': flt(leave_values.get('expired_leaves')),
'used_leaves': flt(leave_values.get('leaves_taken')),
'pending_leaves': flt(leave_values.get('pending_leaves')),
'pending_leaves': flt(leave_values.get('leaves_pending_approval')),
'available_leaves': flt(leave_values.get('remaining_leaves'))
})

View File

@ -26,7 +26,7 @@
"fieldname": "total_allocated_leaves",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Total Allocated Leave",
"label": "Total Allocated Leave(s)",
"no_copy": 1,
"read_only": 1
},
@ -34,7 +34,7 @@
"fieldname": "expired_leaves",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Expired Leave",
"label": "Expired Leave(s)",
"no_copy": 1,
"read_only": 1
},
@ -42,7 +42,7 @@
"fieldname": "used_leaves",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Used Leave",
"label": "Used Leave(s)",
"no_copy": 1,
"read_only": 1
},
@ -50,7 +50,7 @@
"fieldname": "pending_leaves",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Pending Leave",
"label": "Leave(s) Pending Approval",
"no_copy": 1,
"read_only": 1
},
@ -58,7 +58,7 @@
"fieldname": "available_leaves",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Available Leave",
"label": "Available Leave(s)",
"no_copy": 1,
"read_only": 1
}
@ -66,7 +66,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-02-19 10:47:48.546724",
"modified": "2022-02-28 14:01:32.327204",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Salary Slip Leave",
@ -74,5 +74,6 @@
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}