Merge pull request #6018 from rohitwaghchaure/add_calendar_to_timesheets
Added a Calendar view for timesheet logs
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index abcffad..9140927 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -6,6 +6,7 @@
import frappe
from frappe import _
+import json
from datetime import timedelta
from frappe.utils import flt, time_diff_in_hours, get_datetime, getdate, cint, get_datetime_str
from frappe.model.document import Document
@@ -290,3 +291,31 @@
["costing_rate", "billing_rate"], as_dict=True)
return rate[0] if rate else {}
+
+@frappe.whitelist()
+def get_events(start, end, filters=None):
+ """Returns events for Gantt / Calendar view rendering.
+ :param start: Start date-time.
+ :param end: End date-time.
+ :param filters: Filters (JSON).
+ """
+ filters = json.loads(filters)
+
+ conditions = get_conditions(filters)
+ return frappe.db.sql("""select `tabTimesheet Detail`.name as name, `tabTimesheet Detail`.parent as parent,
+ from_time, hours, activity_type, project, to_time from `tabTimesheet Detail`,
+ `tabTimesheet` where `tabTimesheet Detail`.parent = `tabTimesheet`.name and
+ (from_time between %(start)s and %(end)s) {conditions}""".format(conditions=conditions),
+ {
+ "start": start,
+ "end": end
+ }, as_dict=True, update={"allDay": 0})
+
+def get_conditions(filters):
+ conditions = []
+ abbr = {'employee': 'tabTimesheet', 'project': 'tabTimesheet Detail'}
+ for key in filters:
+ if filters.get(key):
+ conditions.append("`%s`.%s = '%s'"%(abbr.get(key), key, filters.get(key)))
+
+ return " and {}".format(" and ".join(conditions)) if conditions else ""
diff --git a/erpnext/projects/doctype/timesheet/timesheet_calendar.js b/erpnext/projects/doctype/timesheet/timesheet_calendar.js
new file mode 100644
index 0000000..6db3e5a
--- /dev/null
+++ b/erpnext/projects/doctype/timesheet/timesheet_calendar.js
@@ -0,0 +1,27 @@
+frappe.views.calendar["Timesheet"] = {
+ field_map: {
+ "start": "from_time",
+ "end": "to_time",
+ "name": "parent",
+ "id": "parent",
+ "title": "activity_type",
+ "allDay": "allDay",
+ "child_name": "name"
+ },
+ gantt: true,
+ filters: [
+ {
+ "fieldtype": "Link",
+ "fieldname": "project",
+ "options": "Project",
+ "label": __("Project")
+ },
+ {
+ "fieldtype": "Link",
+ "fieldname": "employee",
+ "options": "Employee",
+ "label": __("Employee")
+ }
+ ],
+ get_events_method: "erpnext.projects.doctype.timesheet.timesheet.get_events"
+}
\ No newline at end of file