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

100 lines
3.6 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):
project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , ["user", "view_attachments"], as_dict= True)
if frappe.session.user != 'Administrator' and (not project_user or frappe.session.user == 'Guest'):
raise frappe.PermissionError
context.no_cache = 1
2016-04-20 10:50:49 +00:00
context.show_sidebar = True
project = frappe.get_doc('Project', frappe.form_dict.project)
project.has_permission('read')
project.tasks = get_tasks(project.name, start=0, item_status='open',
2016-05-02 06:13:44 +00:00
search=frappe.form_dict.get("search"))
2016-03-23 12:58:50 +00:00
2016-07-05 06:42:39 +00:00
project.timesheets = get_timesheets(project.name, start=0,
search=frappe.form_dict.get("search"))
2016-03-23 12:58:50 +00:00
if project_user and project_user.view_attachments:
project.attachments = get_attachments(project.name)
context.doc = project
2016-03-23 12:58:50 +00:00
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-07-05 06:42:39 +00:00
# if item_status:
# filters["status"] = item_status
2016-03-23 12:58:50 +00:00
tasks = frappe.get_all("Task", filters=filters,
2016-03-29 05:51:42 +00:00
fields=["name", "subject", "status", "_seen", "_comments", "modified", "description"],
2016-03-23 12:58:50 +00:00
limit_start=start, limit_page_length=10)
for task in tasks:
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-29 05:51:42 +00:00
task.comment_count = len(json.loads(task._comments or "[]"))
task.css_seen = ''
if task._seen:
if frappe.session.user in json.loads(task._seen):
task.css_seen = 'seen'
return tasks
@frappe.whitelist()
def get_task_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",
{"doc": {
"name": project,
"project_name": project,
"tasks": get_tasks(project, start, item_status=item_status)}
}, is_path=True)
2016-07-05 06:42:39 +00:00
def get_timesheets(project, start=0, search=None):
filters = {"project": project}
if search:
2016-07-05 06:42:39 +00:00
filters["activity_type"] = ("like", "%{0}%".format(search))
2016-03-23 12:58:50 +00:00
2016-07-05 06:42:39 +00:00
timesheets = frappe.get_all('Timesheet Detail', filters=filters,
fields=['project','activity_type','from_time','to_time','parent'],
2016-03-23 12:58:50 +00:00
limit_start=start, limit_page_length=10)
2016-07-05 06:42:39 +00:00
for timesheet in timesheets:
timesheet.infos = frappe.get_all('Timesheet', filters={"name": timesheet.parent},
fields=['name','_comments','_seen','status','modified','modified_by'],
limit_start=start, limit_page_length=10)
for timesheet.info in timesheet.infos:
timesheet.info.user_image = frappe.db.get_value('User', timesheet.info.modified_by, 'user_image')
timesheet.info.comment_count = len(json.loads(timesheet.info._comments or "[]"))
2016-03-29 05:51:42 +00:00
2016-07-05 06:42:39 +00:00
timesheet.info.css_seen = ''
if timesheet.info._seen:
if frappe.session.user in json.loads(timesheet.info._seen):
timesheet.info.css_seen = 'seen'
2016-07-05 06:42:39 +00:00
return timesheets
@frappe.whitelist()
2016-07-05 06:42:39 +00:00
def get_timesheet_html(project, start=0):
return frappe.render_template("erpnext/templates/includes/projects/project_timesheets.html",
{"doc": {"timesheets": get_timesheets(project, start)}}, is_path=True)
2016-03-23 12:58:50 +00:00
def get_attachments(project):
return frappe.get_all('File', filters= {"attached_to_name": project, "attached_to_doctype": 'Project', "is_private":0},
fields=['file_name','file_url', 'file_size'])