mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 21:49:18 +00:00
Merge pull request #23748 from marination/leave-type-filter
fix(HR) : Filter Leave Type based on allocation for a particular employee (#22050)
This commit is contained in:
@@ -46,6 +46,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
|
|
||||||
make_dashboard: function(frm) {
|
make_dashboard: function(frm) {
|
||||||
var leave_details;
|
var leave_details;
|
||||||
|
let lwps;
|
||||||
if (frm.doc.employee) {
|
if (frm.doc.employee) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_details",
|
method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_details",
|
||||||
@@ -61,6 +62,7 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
if (!r.exc && r.message['leave_approver']) {
|
if (!r.exc && r.message['leave_approver']) {
|
||||||
frm.set_value('leave_approver', r.message['leave_approver']);
|
frm.set_value('leave_approver', r.message['leave_approver']);
|
||||||
}
|
}
|
||||||
|
lwps = r.message["lwps"];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("div").remove(".form-dashboard-section");
|
$("div").remove(".form-dashboard-section");
|
||||||
@@ -70,6 +72,18 @@ frappe.ui.form.on("Leave Application", {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
frm.dashboard.show();
|
frm.dashboard.show();
|
||||||
|
let allowed_leave_types = Object.keys(leave_details);
|
||||||
|
|
||||||
|
// lwps should be allowed, lwps don't have any allocation
|
||||||
|
allowed_leave_types = allowed_leave_types.concat(lwps);
|
||||||
|
|
||||||
|
frm.set_query('leave_type', function(){
|
||||||
|
return {
|
||||||
|
filters : [
|
||||||
|
['leave_type_name', 'in', allowed_leave_types]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class NotAnOptionalHoliday(frappe.ValidationError): pass
|
|||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
class LeaveApplication(Document):
|
class LeaveApplication(Document):
|
||||||
|
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
return _("{0}: From {0} of type {1}").format(self.employee_name, self.leave_type)
|
return _("{0}: From {0} of type {1}").format(self.employee_name, self.leave_type)
|
||||||
|
|
||||||
@@ -451,9 +450,14 @@ def get_leave_details(employee, date):
|
|||||||
"pending_leaves": leaves_pending,
|
"pending_leaves": leaves_pending,
|
||||||
"remaining_leaves": remaining_leaves}
|
"remaining_leaves": remaining_leaves}
|
||||||
|
|
||||||
|
#is used in set query
|
||||||
|
lwps = frappe.get_list("Leave Type", filters = {"is_lwp": 1})
|
||||||
|
lwps = [lwp.name for lwp in lwps]
|
||||||
|
|
||||||
ret = {
|
ret = {
|
||||||
'leave_allocation': leave_allocation,
|
'leave_allocation': leave_allocation,
|
||||||
'leave_approver': get_leave_approver(employee)
|
'leave_approver': get_leave_approver(employee),
|
||||||
|
'lwps': lwps
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
{% if data %}
|
{% if not jQuery.isEmptyObject(data) %}
|
||||||
<h5 style="margin-top: 20px;"> {{ __("Allocated Leaves") }} </h5>
|
<h5 style="margin-top: 20px;"> {{ __("Allocated Leaves") }} </h5>
|
||||||
<table class="table table-bordered small">
|
<table class="table table-bordered small">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
<th style="width: 16%" class="text-right">{{ __("Pending Leaves") }}</th>
|
<th style="width: 16%" class="text-right">{{ __("Pending Leaves") }}</th>
|
||||||
<th style="width: 16%" class="text-right">{{ __("Available Leaves") }}</th>
|
<th style="width: 16%" class="text-right">{{ __("Available Leaves") }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for(const [key, value] of Object.entries(data)) { %}
|
{% for(const [key, value] of Object.entries(data)) { %}
|
||||||
@@ -26,6 +25,6 @@
|
|||||||
{% } %}
|
{% } %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% } else { %}
|
{% else %}
|
||||||
<p style="margin-top: 30px;"> No Leaves have been allocated. </p>
|
<p style="margin-top: 30px;"> No Leaves have been allocated. </p>
|
||||||
{% } %}
|
{% endif %}
|
||||||
Reference in New Issue
Block a user