2016-03-16 12:31:22 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import frappe
|
|
|
|
|
|
|
|
from frappe import _
|
|
|
|
|
|
|
|
def get_context(context):
|
|
|
|
context.no_cache = 1
|
|
|
|
|
|
|
|
project = frappe.get_doc('Project', frappe.form_dict.project)
|
|
|
|
|
|
|
|
project.has_permission('read')
|
|
|
|
|
|
|
|
context.issues = frappe.get_all('Issue', filters={'project': project.project_name},
|
|
|
|
fields=['subject', 'opening_date', 'resolution_date', 'status', 'name', 'resolution_details','modified','modified_by'])
|
|
|
|
|
|
|
|
project.tasks = get_tasks(project.name, start=0, search=frappe.form_dict.get("q"))
|
|
|
|
|
|
|
|
project.timelogs = get_timelogs(project.name, start=0, search=frappe.form_dict.get("q"))
|
|
|
|
|
|
|
|
project.issues = get_issues(project.name, start=0, search=frappe.form_dict.get("q"))
|
|
|
|
|
|
|
|
project.timelines = get_timeline(project.project_name, start=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.doc = project
|
|
|
|
|
|
|
|
|
|
|
|
def get_timeline(project, start=10):
|
|
|
|
issue_names = '({0})'.format(", ".join(["'{0}'".format(i.name) for i in get_issues(project)]))
|
|
|
|
|
|
|
|
|
2016-03-22 10:30:41 +00:00
|
|
|
timelines = frappe.db.sql("""
|
|
|
|
select
|
|
|
|
sender_full_name,
|
|
|
|
subject, communication_date, comment_type, name, creation, modified_by, reference_doctype, reference_name,
|
|
|
|
_liked_by, comment_type, _comments
|
|
|
|
from
|
|
|
|
tabCommunication
|
|
|
|
where
|
|
|
|
(reference_doctype='Project' and reference_name=%s)
|
2016-03-16 12:31:22 +00:00
|
|
|
or (timeline_doctype='Project' and timeline_name=%s)
|
|
|
|
or (reference_doctype='Issue' and reference_name IN {issue_names})
|
2016-03-22 10:30:41 +00:00
|
|
|
order by
|
|
|
|
modified DESC limit {start}, {limit}""".format(
|
2016-03-16 12:31:22 +00:00
|
|
|
issue_names=issue_names, start=start, limit=10),
|
2016-03-22 10:30:41 +00:00
|
|
|
(project, project), as_dict=True);
|
2016-03-16 12:31:22 +00:00
|
|
|
for timeline in timelines:
|
|
|
|
timeline.user_image = frappe.db.get_value('User', timeline.modified_by, 'user_image')
|
|
|
|
return timelines
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-03-22 10:30:41 +00:00
|
|
|
def get_timelines_html(project, start=0):
|
2016-03-16 12:31:22 +00:00
|
|
|
return frappe.render_template("erpnext/templates/includes/projects/timeline.html",
|
|
|
|
{"doc": {"timelines": get_timeline(project, start)}}, is_path=True)
|
|
|
|
|
|
|
|
def get_issue_list(project):
|
|
|
|
return [issue.name for issue in get_issues(project)]
|
|
|
|
|
2016-03-22 10:30:41 +00:00
|
|
|
def get_tasks(project, start=0, search=None, item_status=None):
|
2016-03-16 12:31:22 +00:00
|
|
|
filters = {"project": project}
|
|
|
|
if search:
|
|
|
|
filters["subject"] = ("like", "%{0}%".format(search))
|
2016-03-22 10:30:41 +00:00
|
|
|
if item_status:
|
|
|
|
filters = {"status": item_status}
|
2016-03-16 12:31:22 +00:00
|
|
|
tasks = frappe.get_all("Task", filters=filters,
|
|
|
|
fields=["name", "subject", "status", "exp_start_date", "exp_end_date", "priority"],
|
2016-03-22 10:30:41 +00:00
|
|
|
limit_start=start, limit_page_length=10)
|
2016-03-16 12:31:22 +00:00
|
|
|
|
|
|
|
for task in tasks:
|
2016-03-23 08:44:38 +00:00
|
|
|
print task._comments
|
2016-03-16 12:31:22 +00:00
|
|
|
task.todo = frappe.get_all('ToDo',filters={'reference_name':task.name, 'reference_type':'Task'},
|
|
|
|
fields=["assigned_by", "owner", "modified", "modified_by"])
|
|
|
|
if task.todo:
|
|
|
|
task.todo=task.todo[0]
|
|
|
|
task.todo.user_image = frappe.db.get_value('User', task.todo.owner, 'user_image')
|
2016-03-23 08:44:38 +00:00
|
|
|
if task._comments:
|
|
|
|
task.comment_count = len(json.loads(_comments or "[]"))
|
2016-03-16 12:31:22 +00:00
|
|
|
return tasks
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-03-22 10:30:41 +00:00
|
|
|
def get_tasks_html(project, start=0, item_status=None):
|
2016-03-16 12:31:22 +00:00
|
|
|
return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
|
2016-03-22 10:30:41 +00:00
|
|
|
{"doc": {"tasks": get_tasks(project, start, item_status=item_status)}}, is_path=True)
|
2016-03-16 12:31:22 +00:00
|
|
|
|
|
|
|
|
2016-03-22 10:30:41 +00:00
|
|
|
def get_issues(project, start=0, search=None, item_status=None):
|
2016-03-16 12:31:22 +00:00
|
|
|
filters = {"project": project}
|
|
|
|
if search:
|
|
|
|
filters["subject"] = ("like", "%{0}%".format(search))
|
2016-03-22 10:30:41 +00:00
|
|
|
if item_status:
|
|
|
|
filters = {"status": item_status}
|
2016-03-16 12:31:22 +00:00
|
|
|
issues = frappe.get_all("Issue", filters=filters,
|
|
|
|
fields=["name", "subject", "status", "opening_date", "resolution_date", "resolution_details"],
|
|
|
|
order_by='modified desc',
|
2016-03-22 10:30:41 +00:00
|
|
|
limit_start=start, limit_page_length=10)
|
2016-03-16 12:31:22 +00:00
|
|
|
|
|
|
|
for issue in issues:
|
|
|
|
issue.todo = frappe.get_all('ToDo',filters={'reference_name':issue.name, 'reference_type':'Issue'},
|
|
|
|
fields=["assigned_by", "owner", "modified", "modified_by"])
|
|
|
|
if issue.todo:
|
|
|
|
issue.todo=issue.todo[0]
|
|
|
|
issue.todo.user_image = frappe.db.get_value('User', issue.todo.owner, 'user_image')
|
|
|
|
|
|
|
|
return issues
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-03-22 10:30:41 +00:00
|
|
|
def get_issues_html(project, start=0, item_status=None):
|
2016-03-16 12:31:22 +00:00
|
|
|
return frappe.render_template("erpnext/templates/includes/projects/project_issues.html",
|
2016-03-22 10:30:41 +00:00
|
|
|
{"doc": {"issues": get_issues(project, start, item_status=item_status)}}, is_path=True)
|
2016-03-16 12:31:22 +00:00
|
|
|
|
|
|
|
def get_timelogs(project, start=0, search=None):
|
|
|
|
filters = {"project": project}
|
|
|
|
if search:
|
|
|
|
filters["title"] = ("like", "%{0}%".format(search))
|
|
|
|
|
|
|
|
timelogs = frappe.get_all('Time Log', filters=filters,
|
|
|
|
fields=['name','title','task','activity_type','from_time','to_time','hours','status','modified','modified_by'],
|
2016-03-22 10:30:41 +00:00
|
|
|
limit_start=start, limit_page_length=10)
|
2016-03-16 12:31:22 +00:00
|
|
|
for timelog in timelogs:
|
|
|
|
timelog.user_image = frappe.db.get_value('User', timelog.modified_by, 'user_image')
|
|
|
|
return timelogs
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
|
|
|
def get_timelogs_html(project, start=0):
|
|
|
|
return frappe.render_template("erpnext/templates/includes/projects/project_timelogs.html",
|
|
|
|
{"doc": {"timelogs": get_timelogs(project, start)}}, is_path=True)
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-03-22 10:30:41 +00:00
|
|
|
def set_task_status(project, item_name):
|
|
|
|
task = frappe.get_doc("Task", item_name)
|
2016-03-16 12:31:22 +00:00
|
|
|
task.status = 'Closed'
|
|
|
|
task.save(ignore_permissions=True)
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-03-22 10:30:41 +00:00
|
|
|
def set_issue_status(project, item_name):
|
|
|
|
issue = frappe.get_doc("Issue", item_name)
|
2016-03-16 12:31:22 +00:00
|
|
|
issue.status = 'Closed'
|
|
|
|
issue.save(ignore_permissions=True)
|
|
|
|
|
|
|
|
|