From 5e13799704d0b2336e4eee1e75942dca1b9ab942 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 30 Apr 2015 12:54:55 +0530 Subject: [PATCH] [fixes] leave approver selection and cleaned up layout --- erpnext/hr/doctype/employee/employee.py | 6 +- .../leave_application/leave_application.js | 24 ++--- .../leave_application/leave_application.json | 90 ++++++++++++------- .../leave_application/leave_application.py | 11 +++ .../leave_application_list.js | 2 +- 5 files changed, 80 insertions(+), 53 deletions(-) diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index 5e857f82f3..72a26864ec 100644 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -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: diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js index 2b4bbbdac0..7e72064e6c 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.js +++ b/erpnext/hr/doctype/leave_application/leave_application.js @@ -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) : "")) - } - }) -}) diff --git a/erpnext/hr/doctype/leave_application/leave_application.json b/erpnext/hr/doctype/leave_application/leave_application.json index cb15d42c27..cd32b9c655 100644 --- a/erpnext/hr/doctype/leave_application/leave_application.json +++ b/erpnext/hr/doctype/leave_application/leave_application.json @@ -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", diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index d3bf3587f8..c75c2bd2f2 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -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 diff --git a/erpnext/hr/doctype/leave_application/leave_application_list.js b/erpnext/hr/doctype/leave_application/leave_application_list.js index e0558a7a34..f82dfb2f28 100644 --- a/erpnext/hr/doctype/leave_application/leave_application_list.js +++ b/erpnext/hr/doctype/leave_application/leave_application_list.js @@ -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];