[fixes] leave approver selection and cleaned up layout
This commit is contained in:
parent
4716278f69
commit
5e13799704
@ -6,7 +6,7 @@ import frappe
|
||||
|
||||
from frappe.utils import getdate, validate_email_add, today
|
||||
from frappe.model.naming import make_autoname
|
||||
from frappe import throw, _, msgprint
|
||||
from frappe import throw, _
|
||||
import frappe.permissions
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
@ -139,8 +139,8 @@ class Employee(Document):
|
||||
def validate_employee_leave_approver(self):
|
||||
for l in self.get("leave_approvers")[:]:
|
||||
if "Leave Approver" not in frappe.get_roles(l.leave_approver):
|
||||
self.get("leave_approvers").remove(l)
|
||||
msgprint(_("{0} is not a valid Leave Approver. Removing row #{1}.").format(l.leave_approver, l.idx))
|
||||
frappe.get_doc("User", l.leave_approver).add_roles("Leave Approver")
|
||||
|
||||
|
||||
def validate_reports_to(self):
|
||||
if self.reports_to == self.name:
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
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()});
|
||||
@ -13,7 +17,10 @@ cur_frm.cscript.onload = function(doc, dt, dn) {
|
||||
|
||||
cur_frm.set_query("leave_approver", function() {
|
||||
return {
|
||||
filters: [["UserRole", "role", "=", "Leave Approver"]]
|
||||
query: "erpnext.hr.doctype.leave_application.leave_application.get_approvers",
|
||||
filters: {
|
||||
employee: cur_frm.doc.employee
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@ -106,18 +113,3 @@ cur_frm.cscript.calculate_total_days = function(doc, dt, dn) {
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.employee.get_query = erpnext.queries.employee;
|
||||
|
||||
frappe.ui.form.on("Leave Application", "leave_approver", function(frm) {
|
||||
frappe.call({
|
||||
"method": "frappe.client.get",
|
||||
args: {
|
||||
doctype: "User",
|
||||
name: frm.doc.leave_approver
|
||||
},
|
||||
callback: function (data) {
|
||||
frappe.model.set_value(frm.doctype, frm.docname, "leave_approver_name",
|
||||
data.message.first_name
|
||||
+ (data.message.last_name ? (" " + data.message.last_name) : ""))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -17,17 +17,8 @@
|
||||
"permlevel": 1
|
||||
},
|
||||
{
|
||||
"description": "Leave can be approved by users with Role, \"Leave Approver\"",
|
||||
"fieldname": "leave_approver",
|
||||
"fieldtype": "Link",
|
||||
"label": "Leave Approver",
|
||||
"options": "User",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "leave_approver_name",
|
||||
"fieldtype": "Read Only",
|
||||
"label": "Leave Approver Name",
|
||||
"fieldname": "column_break_12",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
@ -43,6 +34,20 @@
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "leave_balance",
|
||||
"fieldtype": "Float",
|
||||
"label": "Leave Balance Before Application",
|
||||
"no_copy": 1,
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_5",
|
||||
"fieldtype": "Section Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "from_date",
|
||||
"fieldtype": "Date",
|
||||
@ -67,6 +72,15 @@
|
||||
"label": "Half Day",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "total_leave_days",
|
||||
"fieldtype": "Float",
|
||||
"in_list_view": 1,
|
||||
"label": "Total Leave Days",
|
||||
"no_copy": 1,
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break1",
|
||||
"fieldtype": "Column Break",
|
||||
@ -80,6 +94,12 @@
|
||||
"label": "Reason",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_7",
|
||||
"fieldtype": "Section Break",
|
||||
"permlevel": 0,
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "employee",
|
||||
"fieldtype": "Link",
|
||||
@ -101,37 +121,32 @@
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "leave_balance",
|
||||
"fieldtype": "Float",
|
||||
"label": "Leave Balance Before Application",
|
||||
"no_copy": 1,
|
||||
"fieldname": "column_break_15",
|
||||
"fieldtype": "Column Break",
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "total_leave_days",
|
||||
"fieldtype": "Float",
|
||||
"in_list_view": 1,
|
||||
"label": "Total Leave Days",
|
||||
"no_copy": 1,
|
||||
"description": "",
|
||||
"fieldname": "leave_approver",
|
||||
"fieldtype": "Link",
|
||||
"label": "Leave Approver",
|
||||
"options": "User",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "leave_approver_name",
|
||||
"fieldtype": "Read Only",
|
||||
"label": "Leave Approver Name",
|
||||
"permlevel": 0,
|
||||
"read_only": 1
|
||||
"precision": ""
|
||||
},
|
||||
{
|
||||
"fieldname": "sb10",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "More Info",
|
||||
"label": "",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"default": "1",
|
||||
"fieldname": "follow_via_email",
|
||||
"fieldtype": "Check",
|
||||
"label": "Follow via Email",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"default": "Today",
|
||||
"fieldname": "posting_date",
|
||||
@ -152,6 +167,15 @@
|
||||
"reqd": 1,
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"default": "1",
|
||||
"fieldname": "follow_via_email",
|
||||
"fieldtype": "Check",
|
||||
"label": "Follow via Email",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_17",
|
||||
"fieldtype": "Column Break",
|
||||
@ -192,7 +216,7 @@
|
||||
"idx": 1,
|
||||
"is_submittable": 1,
|
||||
"max_attachments": 3,
|
||||
"modified": "2015-02-05 05:11:40.611487",
|
||||
"modified": "2015-04-30 02:19:39.330689",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Leave Application",
|
||||
|
@ -204,6 +204,17 @@ class LeaveApplication(Document):
|
||||
post(**{"txt": args.message, "contact": args.message_to, "subject": args.subject,
|
||||
"notify": cint(self.follow_via_email)})
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_approvers(doctype, txt, searchfield, start, page_len, filters):
|
||||
if not filters.get("employee"):
|
||||
frappe.throw(_("Please select Employee Record first."))
|
||||
|
||||
return frappe.db.sql("""select user.name, user.first_name, user.last_name from
|
||||
tabUser user, `tabEmployee Leave Approver` approver where
|
||||
approver.parent = %s
|
||||
and user.name like %s
|
||||
and approver.leave_approver=user.name""", (filters.get("employee"), "%" + txt + "%"))
|
||||
|
||||
def get_holidays(leave_app):
|
||||
tot_hol = frappe.db.sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2, `tabEmployee` e1
|
||||
where e1.name = %s and h1.parent = h2.name and e1.holiday_list = h2.name
|
||||
|
@ -1,6 +1,6 @@
|
||||
frappe.listview_settings['Leave Application'] = {
|
||||
add_fields: ["status", "leave_type", "employee", "employee_name", "total_leave_days", "from_date"],
|
||||
filters:[["status","!=", "Rejected"], ["to_date", ">=", frappe.datetime.get_today()]],
|
||||
filters:[["status","!=", "Rejected"]],
|
||||
get_indicator: function(doc) {
|
||||
return [__(doc.status), frappe.utils.guess_colour(doc.status),
|
||||
"status,=," + doc.status];
|
||||
|
Loading…
x
Reference in New Issue
Block a user