mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
Added a Calendar view for timesheet logs
This commit is contained in:
committed by
Rohit Waghchaure
parent
595dbd6dea
commit
ed1b8cfe3f
@@ -6,6 +6,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
|
import json
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from frappe.utils import flt, time_diff_in_hours, get_datetime, getdate, cint, get_datetime_str
|
from frappe.utils import flt, time_diff_in_hours, get_datetime, getdate, cint, get_datetime_str
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
@@ -290,3 +291,31 @@ def get_activity_cost(employee=None, activity_type=None):
|
|||||||
["costing_rate", "billing_rate"], as_dict=True)
|
["costing_rate", "billing_rate"], as_dict=True)
|
||||||
|
|
||||||
return rate[0] if rate else {}
|
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 ""
|
||||||
|
|||||||
27
erpnext/projects/doctype/timesheet/timesheet_calendar.js
Normal file
27
erpnext/projects/doctype/timesheet/timesheet_calendar.js
Normal file
@@ -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"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user