brotherton-erpnext/erpnext/templates/pages/projects.py

149 lines
5.3 KiB
Python
Raw Normal View History

# 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
2016-03-23 12:58:50 +00:00
import json
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"))
2016-03-23 12:58:50 +00:00
project.timelogs = get_timelogs(project.name, start=0, search=frappe.form_dict.get("q"))
2016-03-23 12:58:50 +00:00
project.issues = get_issues(project.name, start=0, search=frappe.form_dict.get("q"))
2016-03-23 12:58:50 +00:00
project.timelines = get_timeline(project.project_name, start=0)
2016-03-23 12:58:50 +00:00
context.doc = project
2016-03-23 12:58:50 +00:00
def get_timeline(project, start=10):
2016-03-23 12:58:50 +00:00
'''Get timeline from project, tasks, issues'''
issues_condition = ''
project_issues = get_issues(project)
if project_issues:
issue_names = '({0})'.format(", ".join(["'{0}'".format(i.name) for i in project_issues]))
issues_condition = """or (reference_doctype='Issue' and reference_name IN {issue_names})""".format(issue_names=issue_names)
2016-03-22 10:30:41 +00:00
timelines = frappe.db.sql("""
2016-03-23 12:58:50 +00:00
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
2016-03-22 10:30:41 +00:00
(reference_doctype='Project' and reference_name=%s)
or (timeline_doctype='Project' and timeline_name=%s)
2016-03-23 12:58:50 +00:00
{issues_condition}
order by
2016-03-22 10:30:41 +00:00
modified DESC limit {start}, {limit}""".format(
2016-03-23 12:58:50 +00:00
issues_condition=issues_condition, start=start, limit=10),
2016-03-22 10:30:41 +00:00
(project, project), as_dict=True);
for timeline in timelines:
timeline.user_image = frappe.db.get_value('User', timeline.modified_by, 'user_image')
2016-03-23 12:58:50 +00:00
return timelines
@frappe.whitelist()
2016-03-22 10:30:41 +00:00
def get_timelines_html(project, start=0):
2016-03-23 12:58:50 +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):
filters = {"project": project}
if search:
filters["subject"] = ("like", "%{0}%".format(search))
2016-03-23 12:58:50 +00:00
if item_status:
2016-03-25 06:34:54 +00:00
filters["status"] = item_status
2016-03-23 12:58:50 +00:00
tasks = frappe.get_all("Task", filters=filters,
fields=["name", "subject", "status", "exp_start_date", "exp_end_date", "priority"],
limit_start=start, limit_page_length=10)
for task in tasks:
print task._comments
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')
if task._comments:
2016-03-23 12:58:50 +00:00
task.comment_count = len(json.loads(task._comments or "[]"))
return tasks
@frappe.whitelist()
2016-03-22 10:30:41 +00:00
def get_tasks_html(project, start=0, item_status=None):
2016-03-23 12:58:50 +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-23 12:58:50 +00:00
2016-03-22 10:30:41 +00:00
def get_issues(project, start=0, search=None, item_status=None):
filters = {"project": project}
if search:
filters["subject"] = ("like", "%{0}%".format(search))
2016-03-23 12:58:50 +00:00
if item_status:
2016-03-25 06:34:54 +00:00
filters["status"] = item_status
2016-03-23 12:58:50 +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-23 12:58:50 +00:00
limit_start=start, limit_page_length=10)
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')
2016-03-23 12:58:50 +00:00
return issues
@frappe.whitelist()
2016-03-22 10:30:41 +00:00
def get_issues_html(project, start=0, item_status=None):
2016-03-23 12:58:50 +00:00
return frappe.render_template("erpnext/templates/includes/projects/project_issues.html",
{"doc": {"issues": get_issues(project, start, item_status=item_status)}}, is_path=True)
def get_timelogs(project, start=0, search=None):
filters = {"project": project}
if search:
filters["title"] = ("like", "%{0}%".format(search))
2016-03-23 12:58:50 +00:00
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-23 12:58:50 +00:00
limit_start=start, limit_page_length=10)
for timelog in timelogs:
2016-03-23 12:58:50 +00:00
timelog.user_image = frappe.db.get_value('User', timelog.modified_by, 'user_image')
return timelogs
@frappe.whitelist()
def get_timelogs_html(project, start=0):
2016-03-23 12:58:50 +00:00
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)
task.status = 'Closed'
task.save(ignore_permissions=True)
2016-03-23 12:58:50 +00:00
@frappe.whitelist()
2016-03-22 10:30:41 +00:00
def set_issue_status(project, item_name):
issue = frappe.get_doc("Issue", item_name)
issue.status = 'Closed'
issue.save(ignore_permissions=True)
2016-03-23 12:58:50 +00:00