blob: 86f064c32eae484d80ae1cf3b421f94043005d0f [file] [log] [blame]
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5import frappe
Rushabh Mehtab2269dd2016-03-23 18:28:50 +05306import json
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +05307
8def get_context(context):
9 context.no_cache = 1
10
11 project = frappe.get_doc('Project', frappe.form_dict.project)
12
13 project.has_permission('read')
Kanchan Chauhanb566d422016-03-29 11:21:42 +053014
Rushabh Mehtac20c5362016-03-25 17:19:28 +053015 project.tasks = get_tasks(project.name, start=0, item_status='open',
16 search=frappe.form_dict.get("q"))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053017
Rushabh Mehtac20c5362016-03-25 17:19:28 +053018 project.timelogs = get_timelogs(project.name, start=0,
19 search=frappe.form_dict.get("q"))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053020
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053021
22 context.doc = project
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053023
24
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053025def get_tasks(project, start=0, search=None, item_status=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053026 filters = {"project": project}
27 if search:
28 filters["subject"] = ("like", "%{0}%".format(search))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053029 if item_status:
Kanchan Chauhan53ce94f2016-03-25 12:04:54 +053030 filters["status"] = item_status
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053031 tasks = frappe.get_all("Task", filters=filters,
Kanchan Chauhanb566d422016-03-29 11:21:42 +053032 fields=["name", "subject", "status", "_seen", "_comments", "modified", "description"],
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053033 limit_start=start, limit_page_length=10)
34
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053035 for task in tasks:
36 task.todo = frappe.get_all('ToDo',filters={'reference_name':task.name, 'reference_type':'Task'},
37 fields=["assigned_by", "owner", "modified", "modified_by"])
Rushabh Mehtac20c5362016-03-25 17:19:28 +053038
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053039 if task.todo:
40 task.todo=task.todo[0]
41 task.todo.user_image = frappe.db.get_value('User', task.todo.owner, 'user_image')
Rushabh Mehtac20c5362016-03-25 17:19:28 +053042
Kanchan Chauhanb566d422016-03-29 11:21:42 +053043
44 task.comment_count = len(json.loads(task._comments or "[]"))
Rushabh Mehtac20c5362016-03-25 17:19:28 +053045
46 task.css_seen = ''
47 if task._seen:
48 if frappe.session.user in json.loads(task._seen):
49 task.css_seen = 'seen'
50
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053051 return tasks
52
53@frappe.whitelist()
Rushabh Mehtac20c5362016-03-25 17:19:28 +053054def get_task_html(project, start=0, item_status=None):
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053055 return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
Rushabh Mehtac20c5362016-03-25 17:19:28 +053056 {"doc": {
57 "name": project,
58 "project_name": project,
59 "tasks": get_tasks(project, start, item_status=item_status)}
60 }, is_path=True)
61
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053062def get_timelogs(project, start=0, search=None):
63 filters = {"project": project}
64 if search:
65 filters["title"] = ("like", "%{0}%".format(search))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053066
67 timelogs = frappe.get_all('Time Log', filters=filters,
Kanchan Chauhanb566d422016-03-29 11:21:42 +053068 fields=['name','title','task','activity_type','from_time','to_time','_comments','_seen','status','modified','modified_by'],
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053069 limit_start=start, limit_page_length=10)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053070 for timelog in timelogs:
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053071 timelog.user_image = frappe.db.get_value('User', timelog.modified_by, 'user_image')
Kanchan Chauhanb566d422016-03-29 11:21:42 +053072
73 timelog.comment_count = len(json.loads(timelog._comments or "[]"))
74
75 timelog.css_seen = ''
76 if timelog._seen:
77 if frappe.session.user in json.loads(timelog._seen):
78 timelog.css_seen = 'seen'
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053079 return timelogs
80
81@frappe.whitelist()
Rushabh Mehtac20c5362016-03-25 17:19:28 +053082def get_timelog_html(project, start=0):
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053083 return frappe.render_template("erpnext/templates/includes/projects/project_timelogs.html",
84 {"doc": {"timelogs": get_timelogs(project, start)}}, is_path=True)
85