Merge pull request #4212 from anandpdoshi/leave-application-js-clenup

[minor] leave application cleanup
This commit is contained in:
Anand Doshi 2015-10-22 15:19:57 +05:30
commit e99fff8d08

View File

@ -3,113 +3,116 @@
cur_frm.add_fetch('employee','employee_name','employee_name');
frappe.ui.form.on("Leave Application", "leave_approver", function(frm) {
frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
});
cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.posting_date)
set_multiple(dt,dn,{posting_date:get_today()});
if(doc.__islocal) {
cur_frm.set_value("status", "Open");
cur_frm.cscript.calculate_total_days(doc, dt, dn);
frappe.ui.form.on("Leave Application", {
onload: function(frm) {
if (!frm.doc.posting_date) {
frm.set_value("posting_date", get_today());
}
cur_frm.set_query("leave_approver", function() {
frm.set_query("leave_approver", function() {
return {
query: "erpnext.hr.doctype.leave_application.leave_application.get_approvers",
filters: {
employee: cur_frm.doc.employee
employee: frm.doc.employee
}
};
});
cur_frm.cscript.get_leave_balance(cur_frm.doc);
frm.set_query("employee", erpnext.queries.employee);
},
refresh: function(frm) {
if (frm.is_new()) {
frm.set_value("status", "Open");
frm.trigger("calculate_total_days");
}
cur_frm.cscript.refresh = function(doc, dt, dn) {
if(doc.__islocal) {
cur_frm.set_value("status", "Open")
}
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("");
if (frm.is_new() && !in_list(user_roles, "HR User")) {
frm.set_intro(__("Fill the form and save it"));
} else {
if(doc.docstatus==0 && doc.status=="Open") {
if(user==doc.leave_approver) {
cur_frm.set_intro(__("You are the Leave Approver for this record. Please Update the 'Status' and Save"));
cur_frm.toggle_enable("status", true);
if(frm.doc.docstatus==0 && frm.doc.status=="Open") {
if(user==frm.doc.leave_approver) {
frm.set_intro(__("You are the Leave Approver for this record. Please Update the 'Status' and Save"));
frm.toggle_enable("status", true);
} else {
cur_frm.set_intro(__("This Leave Application is pending approval. Only the Leave Approver can update status."))
cur_frm.toggle_enable("status", false);
}
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){
cur_frm.cscript.get_leave_balance(doc, dt, dn);
}
leave_approver: function(frm) {
frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
},
cur_frm.cscript.fiscal_year = function (doc, dt, dn){
cur_frm.cscript.get_leave_balance(doc, dt, dn);
}
employee: function(frm) {
frm.trigger("get_leave_balance");
},
cur_frm.cscript.leave_type = function (doc, dt, dn){
cur_frm.cscript.get_leave_balance(doc, dt, dn);
}
fiscal_year: function(frm) {
frm.trigger("get_leave_balance");
},
cur_frm.cscript.half_day = function(doc, dt, dn) {
if(doc.from_date) {
set_multiple(dt,dn,{to_date:doc.from_date});
cur_frm.cscript.calculate_total_days(doc, dt, dn);
}
}
leave_type: function(frm) {
frm.trigger("get_leave_balance");
},
cur_frm.cscript.from_date = function(doc, dt, dn) {
if(cint(doc.half_day) == 1){
set_multiple(dt,dn,{to_date:doc.from_date});
}
cur_frm.cscript.calculate_total_days(doc, dt, dn);
half_day: function(frm) {
if (frm.doc.from_date) {
frm.set_value("to_date", frm.doc.from_date);
frm.trigger("calculate_total_days");
}
},
cur_frm.cscript.to_date = function(doc, dt, dn) {
if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){
from_date: function(frm) {
if (cint(frm.doc.half_day)==1) {
frm.set_value("to_date", frm.doc.from_date);
}
frm.trigger("calculate_total_days");
},
to_date: function(frm) {
if (cint(frm.doc.half_day)==1 && cstr(frm.doc.from_date) && frm.doc.from_date != frm.doc.to_date) {
msgprint(__("To Date should be same as From Date for Half Day leave"));
set_multiple(dt,dn,{to_date:doc.from_date});
}
cur_frm.cscript.calculate_total_days(doc, dt, dn);
frm.set_value("to_date", frm.doc.from_date);
}
cur_frm.cscript.get_leave_balance = function(doc, dt, dn) {
if(doc.docstatus==0 && doc.employee && doc.leave_type && doc.fiscal_year) {
return cur_frm.call({
frm.trigger("calculate_total_days");
},
get_leave_balance: function(frm) {
if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.fiscal_year) {
return frm.call({
method: "get_leave_balance",
args: {
employee: doc.employee,
fiscal_year: doc.fiscal_year,
leave_type: doc.leave_type
employee: frm.doc.employee,
fiscal_year: frm.doc.fiscal_year,
leave_type: frm.doc.leave_type
}
});
}
}
},
cur_frm.cscript.calculate_total_days = function(doc, dt, dn) {
if(doc.from_date && doc.to_date){
if(cint(doc.half_day) == 1) set_multiple(dt,dn,{total_leave_days:0.5});
else{
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: doc},
args: { leave_app: frm.doc },
callback: function(response) {
if (response && response.message) {
cur_frm.set_value('total_leave_days', response.message.total_leave_days);
frm.set_value('total_leave_days', response.message.total_leave_days);
}
}
});
}
}
}
},
cur_frm.fields_dict.employee.get_query = erpnext.queries.employee;
});