From 9249f354cd5ede82b53c09ed4b781087fc51c707 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 15 Feb 2013 19:28:05 +0530 Subject: [PATCH] added view selector and calendar view for leave application --- home/page/latest_updates/latest_updates.js | 4 ++ .../leave_application/leave_application.py | 58 ++++++++++++++++++- .../leave_application_calendar.js | 10 ++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 hr/doctype/leave_application/leave_application_calendar.js diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js index a3f37607b9..42408de3b7 100644 --- a/home/page/latest_updates/latest_updates.js +++ b/home/page/latest_updates/latest_updates.js @@ -1,4 +1,8 @@ erpnext.updates = [ + ["15th February, 2013", [ + "Calendar: Added new FullCalendar, and Calendar Views", + "Leave Application: Added email notifications on Leave Application", + ]], ["13th February, 2013", [ "Employee: If Employee is linked to a Profile, copy Full Name, Date of Birth, \ Image and Gender to Profile", diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index 17f8526f2d..1fae2409b5 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -152,4 +152,60 @@ def get_approver_list(): def is_lwp(leave_type): lwp = webnotes.conn.sql("select is_lwp from `tabLeave Type` where name = %s", leave_type) - return lwp and cint(lwp[0][0]) or 0 \ No newline at end of file + return lwp and cint(lwp[0][0]) or 0 + +@webnotes.whitelist() +def get_events(start, end): + events = [] + employee = webnotes.conn.get_default("employee", webnotes.session.user) + company = webnotes.conn.get_default("company", webnotes.session.user) + + add_department_leaves(events, start, end, employee, company) + add_block_dates(events, start, end, employee, company) + return events + +def add_department_leaves(events, start, end, employee, company): + department = webnotes.conn.get_value("Employee", employee, "department") + + if not department: + return + + # department leaves + department_employees = webnotes.conn.sql_list("select name from tabEmployee where department=%s", + department) + + for d in webnotes.conn.sql("""select name, from_date, to_date, employee_name, half_day, + status, employee + from `tabLeave Application` where + (from_date between %s and %s or to_date between %s and %s) + and docstatus < 2 + and status!="Rejected" + and employee in ('%s')""" % ("%s", "%s", "%s", "%s", "', '".join(department_employees)), + (start, end, start, end), as_dict=True): + events.append({ + "name": d.name, + "doctype": "Leave Application", + "from_date": d.from_date, + "to_date": d.to_date, + "status": d.status, + "title": _("Leave by") + " " + d.employee_name + \ + (d.half_day and _(" (Half Day)") or "") + }) + + +def add_block_dates(events, start, end, employee, company): + # block days + from hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates + + cnt = 0 + block_dates = get_applicable_block_dates(start, end, employee, company, all_lists=True) + + for block_date in block_dates: + events.append({ + "doctype": "Leave Block List Date", + "from_date": block_date.block_date, + "title": _("Leave Blocked") + ": " + block_date.reason, + "name": "_" + str(cnt), + }) + cnt+=1 + diff --git a/hr/doctype/leave_application/leave_application_calendar.js b/hr/doctype/leave_application/leave_application_calendar.js new file mode 100644 index 0000000000..eebd5590a5 --- /dev/null +++ b/hr/doctype/leave_application/leave_application_calendar.js @@ -0,0 +1,10 @@ +wn.views.calendar["Leave Application"] = wn.views.Calendar.extend({ + field_map: { + "start": "from_date", + "end": "to_date", + "id": "name", + "title": "title", + "status": "status", + }, + get_events_method: "hr.doctype.leave_application.leave_application.get_events" +}) \ No newline at end of file