[Fix] onload set default employee, leave approver, company
This commit is contained in:
parent
4ea97c84ac
commit
8e4f676c8c
@ -15,6 +15,10 @@ from erpnext.accounts.report.cash_flow.cash_flow import (get_cash_flow_accounts,
|
||||
|
||||
def execute(filters=None):
|
||||
columns, data, message, chart = [], [], [], []
|
||||
|
||||
if not filters.get('company'):
|
||||
return columns, data, message, chart
|
||||
|
||||
fiscal_year = get_fiscal_year_data(filters.get('from_fiscal_year'), filters.get('to_fiscal_year'))
|
||||
companies_column, companies = get_companies(filters)
|
||||
columns = get_columns(companies_column)
|
||||
|
@ -50,8 +50,11 @@ frappe.ui.form.on("Leave Application", {
|
||||
date: frm.doc.posting_date
|
||||
},
|
||||
callback: function(r) {
|
||||
if (!r.exc && r.message) {
|
||||
leave_details = r.message;
|
||||
if (!r.exc && r.message['leave_allocation']) {
|
||||
leave_details = r.message['leave_allocation'];
|
||||
}
|
||||
if (!r.exc && r.message['leave_approver']) {
|
||||
frm.set_value('leave_approver', r.message['leave_approver']);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -74,6 +77,13 @@ frappe.ui.form.on("Leave Application", {
|
||||
if(frm.doc.__islocal && !in_list(frappe.user_roles, "Employee")) {
|
||||
frm.set_intro(__("Fill the form and save it"));
|
||||
}
|
||||
|
||||
if (!frm.doc.employee && frappe.defaults.get_user_permissions()) {
|
||||
const perm = frappe.defaults.get_user_permissions();
|
||||
if (perm && perm['Employee']) {
|
||||
frm.set_value('employee', perm['Employee']["docs"][0])
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
employee: function(frm) {
|
||||
|
@ -374,7 +374,12 @@ def get_leave_details(employee, date):
|
||||
"pending_leaves": leaves_pending,
|
||||
"remaining_leaves": remaining_leaves}
|
||||
|
||||
return leave_allocation
|
||||
ret = {
|
||||
'leave_allocation': leave_allocation,
|
||||
'leave_approver': get_leave_approver(employee)
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
|
||||
@ -603,3 +608,10 @@ def get_approved_leaves_for_period(employee, leave_type, from_date, to_date):
|
||||
|
||||
return leave_days
|
||||
|
||||
def get_leave_approver(employee, department=None):
|
||||
if not department:
|
||||
department = frappe.db.get_value('Employee', employee, 'department')
|
||||
|
||||
if department:
|
||||
return frappe.db.get_value('Department Approver', {'parent': department,
|
||||
'parentfield': 'leave_approver', 'idx': 1}, 'approver')
|
||||
|
Loading…
x
Reference in New Issue
Block a user