blob: 758113f6607436b7d385fbe66d30b5842fabfa8e [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
6
7from frappe import _
8
9def get_context(context):
10 context.no_cache = 1
11
12 project = frappe.get_doc('Project', frappe.form_dict.project)
13
14 project.has_permission('read')
15
16 context.issues = frappe.get_all('Issue', filters={'project': project.project_name},
17 fields=['subject', 'opening_date', 'resolution_date', 'status', 'name', 'resolution_details','modified','modified_by'])
18
19 project.tasks = get_tasks(project.name, start=0, search=frappe.form_dict.get("q"))
20
21 project.timelogs = get_timelogs(project.name, start=0, search=frappe.form_dict.get("q"))
22
23 project.issues = get_issues(project.name, start=0, search=frappe.form_dict.get("q"))
24
25 project.timelines = get_timeline(project.project_name, start=0)
26
27
28
29 context.doc = project
30
31
32def get_timeline(project, start=10):
33 issue_names = '({0})'.format(", ".join(["'{0}'".format(i.name) for i in get_issues(project)]))
34
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053035
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053036 timelines = frappe.db.sql("""
37 select
38 sender_full_name,
39 subject, communication_date, comment_type, name, creation, modified_by, reference_doctype, reference_name,
40 _liked_by, comment_type, _comments
41 from
42 tabCommunication
43 where
44 (reference_doctype='Project' and reference_name=%s)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053045 or (timeline_doctype='Project' and timeline_name=%s)
46 or (reference_doctype='Issue' and reference_name IN {issue_names})
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053047 order by
48 modified DESC limit {start}, {limit}""".format(
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053049 issue_names=issue_names, start=start, limit=10),
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053050 (project, project), as_dict=True);
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053051 for timeline in timelines:
52 timeline.user_image = frappe.db.get_value('User', timeline.modified_by, 'user_image')
53 return timelines
54
55@frappe.whitelist()
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053056def get_timelines_html(project, start=0):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053057 return frappe.render_template("erpnext/templates/includes/projects/timeline.html",
58 {"doc": {"timelines": get_timeline(project, start)}}, is_path=True)
59
60def get_issue_list(project):
61 return [issue.name for issue in get_issues(project)]
62
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053063def get_tasks(project, start=0, search=None, item_status=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053064 filters = {"project": project}
65 if search:
66 filters["subject"] = ("like", "%{0}%".format(search))
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053067 if item_status:
68 filters = {"status": item_status}
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053069 tasks = frappe.get_all("Task", filters=filters,
70 fields=["name", "subject", "status", "exp_start_date", "exp_end_date", "priority"],
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053071 limit_start=start, limit_page_length=10)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053072
73 for task in tasks:
74 task.todo = frappe.get_all('ToDo',filters={'reference_name':task.name, 'reference_type':'Task'},
75 fields=["assigned_by", "owner", "modified", "modified_by"])
76 if task.todo:
77 task.todo=task.todo[0]
78 task.todo.user_image = frappe.db.get_value('User', task.todo.owner, 'user_image')
79
80 return tasks
81
82@frappe.whitelist()
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053083def get_tasks_html(project, start=0, item_status=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053084 return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053085 {"doc": {"tasks": get_tasks(project, start, item_status=item_status)}}, is_path=True)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053086
87
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053088def get_issues(project, start=0, search=None, item_status=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053089 filters = {"project": project}
90 if search:
91 filters["subject"] = ("like", "%{0}%".format(search))
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053092 if item_status:
93 filters = {"status": item_status}
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053094 issues = frappe.get_all("Issue", filters=filters,
95 fields=["name", "subject", "status", "opening_date", "resolution_date", "resolution_details"],
96 order_by='modified desc',
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053097 limit_start=start, limit_page_length=10)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053098
99 for issue in issues:
100 issue.todo = frappe.get_all('ToDo',filters={'reference_name':issue.name, 'reference_type':'Issue'},
101 fields=["assigned_by", "owner", "modified", "modified_by"])
102 if issue.todo:
103 issue.todo=issue.todo[0]
104 issue.todo.user_image = frappe.db.get_value('User', issue.todo.owner, 'user_image')
105
106 return issues
107
108@frappe.whitelist()
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +0530109def get_issues_html(project, start=0, item_status=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530110 return frappe.render_template("erpnext/templates/includes/projects/project_issues.html",
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +0530111 {"doc": {"issues": get_issues(project, start, item_status=item_status)}}, is_path=True)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530112
113def get_timelogs(project, start=0, search=None):
114 filters = {"project": project}
115 if search:
116 filters["title"] = ("like", "%{0}%".format(search))
117
118 timelogs = frappe.get_all('Time Log', filters=filters,
119 fields=['name','title','task','activity_type','from_time','to_time','hours','status','modified','modified_by'],
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +0530120 limit_start=start, limit_page_length=10)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530121 for timelog in timelogs:
122 timelog.user_image = frappe.db.get_value('User', timelog.modified_by, 'user_image')
123 return timelogs
124
125@frappe.whitelist()
126def get_timelogs_html(project, start=0):
127 return frappe.render_template("erpnext/templates/includes/projects/project_timelogs.html",
128 {"doc": {"timelogs": get_timelogs(project, start)}}, is_path=True)
129
130@frappe.whitelist()
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +0530131def set_task_status(project, item_name):
132 task = frappe.get_doc("Task", item_name)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530133 task.status = 'Closed'
134 task.save(ignore_permissions=True)
135
136@frappe.whitelist()
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +0530137def set_issue_status(project, item_name):
138 issue = frappe.get_doc("Issue", item_name)
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +0530139 issue.status = 'Closed'
140 issue.save(ignore_permissions=True)
141
142