Merge pull request #4212 from anandpdoshi/leave-application-js-clenup
[minor] leave application cleanup
This commit is contained in:
commit
e99fff8d08
@ -3,113 +3,116 @@
|
|||||||
|
|
||||||
cur_frm.add_fetch('employee','employee_name','employee_name');
|
cur_frm.add_fetch('employee','employee_name','employee_name');
|
||||||
|
|
||||||
frappe.ui.form.on("Leave Application", "leave_approver", function(frm) {
|
frappe.ui.form.on("Leave Application", {
|
||||||
frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
|
onload: function(frm) {
|
||||||
});
|
if (!frm.doc.posting_date) {
|
||||||
|
frm.set_value("posting_date", get_today());
|
||||||
|
}
|
||||||
|
|
||||||
cur_frm.cscript.onload = function(doc, dt, dn) {
|
frm.set_query("leave_approver", function() {
|
||||||
if(!doc.posting_date)
|
return {
|
||||||
set_multiple(dt,dn,{posting_date:get_today()});
|
query: "erpnext.hr.doctype.leave_application.leave_application.get_approvers",
|
||||||
if(doc.__islocal) {
|
filters: {
|
||||||
cur_frm.set_value("status", "Open");
|
employee: frm.doc.employee
|
||||||
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
}
|
||||||
}
|
};
|
||||||
|
});
|
||||||
|
|
||||||
cur_frm.set_query("leave_approver", function() {
|
frm.set_query("employee", erpnext.queries.employee);
|
||||||
return {
|
|
||||||
query: "erpnext.hr.doctype.leave_application.leave_application.get_approvers",
|
|
||||||
filters: {
|
|
||||||
employee: cur_frm.doc.employee
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
cur_frm.cscript.get_leave_balance(cur_frm.doc);
|
},
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.refresh = function(doc, dt, dn) {
|
refresh: function(frm) {
|
||||||
if(doc.__islocal) {
|
if (frm.is_new()) {
|
||||||
cur_frm.set_value("status", "Open")
|
frm.set_value("status", "Open");
|
||||||
}
|
frm.trigger("calculate_total_days");
|
||||||
cur_frm.set_intro("");
|
}
|
||||||
if(doc.__islocal && !in_list(user_roles, "HR User")) {
|
|
||||||
cur_frm.set_intro(__("Fill the form and save it"))
|
frm.set_intro("");
|
||||||
} else {
|
if (frm.is_new() && !in_list(user_roles, "HR User")) {
|
||||||
if(doc.docstatus==0 && doc.status=="Open") {
|
frm.set_intro(__("Fill the form and save it"));
|
||||||
if(user==doc.leave_approver) {
|
} else {
|
||||||
cur_frm.set_intro(__("You are the Leave Approver for this record. Please Update the 'Status' and Save"));
|
if(frm.doc.docstatus==0 && frm.doc.status=="Open") {
|
||||||
cur_frm.toggle_enable("status", true);
|
if(user==frm.doc.leave_approver) {
|
||||||
} else {
|
frm.set_intro(__("You are the Leave Approver for this record. Please Update the 'Status' and Save"));
|
||||||
cur_frm.set_intro(__("This Leave Application is pending approval. Only the Leave Approver can update status."))
|
frm.toggle_enable("status", true);
|
||||||
cur_frm.toggle_enable("status", false);
|
} else {
|
||||||
|
frm.set_intro(__("This Leave Application is pending approval. Only the Leave Approver can update status."))
|
||||||
|
frm.toggle_enable("status", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.employee = function (doc, dt, dn){
|
leave_approver: function(frm) {
|
||||||
cur_frm.cscript.get_leave_balance(doc, dt, dn);
|
frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
|
||||||
}
|
},
|
||||||
|
|
||||||
cur_frm.cscript.fiscal_year = function (doc, dt, dn){
|
employee: function(frm) {
|
||||||
cur_frm.cscript.get_leave_balance(doc, dt, dn);
|
frm.trigger("get_leave_balance");
|
||||||
}
|
},
|
||||||
|
|
||||||
cur_frm.cscript.leave_type = function (doc, dt, dn){
|
fiscal_year: function(frm) {
|
||||||
cur_frm.cscript.get_leave_balance(doc, dt, dn);
|
frm.trigger("get_leave_balance");
|
||||||
}
|
},
|
||||||
|
|
||||||
cur_frm.cscript.half_day = function(doc, dt, dn) {
|
leave_type: function(frm) {
|
||||||
if(doc.from_date) {
|
frm.trigger("get_leave_balance");
|
||||||
set_multiple(dt,dn,{to_date:doc.from_date});
|
},
|
||||||
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.from_date = function(doc, dt, dn) {
|
half_day: function(frm) {
|
||||||
if(cint(doc.half_day) == 1){
|
if (frm.doc.from_date) {
|
||||||
set_multiple(dt,dn,{to_date:doc.from_date});
|
frm.set_value("to_date", frm.doc.from_date);
|
||||||
}
|
frm.trigger("calculate_total_days");
|
||||||
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
cur_frm.cscript.to_date = function(doc, dt, dn) {
|
from_date: function(frm) {
|
||||||
if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){
|
if (cint(frm.doc.half_day)==1) {
|
||||||
msgprint(__("To Date should be same as From Date for Half Day leave"));
|
frm.set_value("to_date", frm.doc.from_date);
|
||||||
set_multiple(dt,dn,{to_date:doc.from_date});
|
}
|
||||||
}
|
frm.trigger("calculate_total_days");
|
||||||
cur_frm.cscript.calculate_total_days(doc, dt, dn);
|
},
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.get_leave_balance = function(doc, dt, dn) {
|
to_date: function(frm) {
|
||||||
if(doc.docstatus==0 && doc.employee && doc.leave_type && doc.fiscal_year) {
|
if (cint(frm.doc.half_day)==1 && cstr(frm.doc.from_date) && frm.doc.from_date != frm.doc.to_date) {
|
||||||
return cur_frm.call({
|
msgprint(__("To Date should be same as From Date for Half Day leave"));
|
||||||
method: "get_leave_balance",
|
frm.set_value("to_date", frm.doc.from_date);
|
||||||
args: {
|
}
|
||||||
employee: doc.employee,
|
|
||||||
fiscal_year: doc.fiscal_year,
|
|
||||||
leave_type: doc.leave_type
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.calculate_total_days = function(doc, dt, dn) {
|
frm.trigger("calculate_total_days");
|
||||||
if(doc.from_date && doc.to_date){
|
},
|
||||||
if(cint(doc.half_day) == 1) set_multiple(dt,dn,{total_leave_days:0.5});
|
|
||||||
else{
|
get_leave_balance: function(frm) {
|
||||||
// server call is done to include holidays in leave days calculations
|
if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.fiscal_year) {
|
||||||
return frappe.call({
|
return frm.call({
|
||||||
method: 'erpnext.hr.doctype.leave_application.leave_application.get_total_leave_days',
|
method: "get_leave_balance",
|
||||||
args: {leave_app: doc},
|
args: {
|
||||||
callback: function(response) {
|
employee: frm.doc.employee,
|
||||||
if (response && response.message) {
|
fiscal_year: frm.doc.fiscal_year,
|
||||||
cur_frm.set_value('total_leave_days', response.message.total_leave_days);
|
leave_type: frm.doc.leave_type
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.fields_dict.employee.get_query = erpnext.queries.employee;
|
calculate_total_days: function(frm) {
|
||||||
|
if(frm.doc.from_date && frm.doc.to_date) {
|
||||||
|
if (cint(frm.doc.half_day)==1) {
|
||||||
|
frm.set_value("total_leave_days", 0.5);
|
||||||
|
} else {
|
||||||
|
// server call is done to include holidays in leave days calculations
|
||||||
|
return frappe.call({
|
||||||
|
method: 'erpnext.hr.doctype.leave_application.leave_application.get_total_leave_days',
|
||||||
|
args: { leave_app: frm.doc },
|
||||||
|
callback: function(response) {
|
||||||
|
if (response && response.message) {
|
||||||
|
frm.set_value('total_leave_days', response.message.total_leave_days);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user