2016-03-16 18:01:22 +05:30
|
|
|
# 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 18:28:50 +05:30
|
|
|
import json
|
2016-03-16 18:01:22 +05:30
|
|
|
|
|
|
|
def get_context(context):
|
2018-09-10 13:40:43 +02:00
|
|
|
project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , ["user", "view_attachments"], as_dict= True)
|
2019-07-16 09:40:09 +05:30
|
|
|
if frappe.session.user != 'Administrator' and (not project_user or frappe.session.user == 'Guest'):
|
2016-04-08 23:22:04 +05:30
|
|
|
raise frappe.PermissionError
|
2019-07-16 09:40:09 +05:30
|
|
|
|
2016-03-16 18:01:22 +05:30
|
|
|
context.no_cache = 1
|
2016-04-20 16:20:49 +05:30
|
|
|
context.show_sidebar = True
|
2016-03-16 18:01:22 +05:30
|
|
|
project = frappe.get_doc('Project', frappe.form_dict.project)
|
|
|
|
|
|
|
|
project.has_permission('read')
|
2019-07-16 09:40:09 +05:30
|
|
|
|
2016-03-25 17:19:28 +05:30
|
|
|
project.tasks = get_tasks(project.name, start=0, item_status='open',
|
2016-05-02 11:43:44 +05:30
|
|
|
search=frappe.form_dict.get("search"))
|
2016-03-23 18:28:50 +05:30
|
|
|
|
2016-07-05 12:12:39 +05:30
|
|
|
project.timesheets = get_timesheets(project.name, start=0,
|
|
|
|
search=frappe.form_dict.get("search"))
|
2016-03-23 18:28:50 +05:30
|
|
|
|
2019-07-16 09:40:09 +05:30
|
|
|
if project_user and project_user.view_attachments:
|
2018-09-10 13:40:43 +02:00
|
|
|
project.attachments = get_attachments(project.name)
|
2016-03-16 18:01:22 +05:30
|
|
|
|
|
|
|
context.doc = project
|
2016-03-23 18:28:50 +05:30
|
|
|
|
|
|
|
|
2016-03-22 16:00:41 +05:30
|
|
|
def get_tasks(project, start=0, search=None, item_status=None):
|
2016-03-16 18:01:22 +05:30
|
|
|
filters = {"project": project}
|
|
|
|
if search:
|
|
|
|
filters["subject"] = ("like", "%{0}%".format(search))
|
2016-03-23 18:28:50 +05:30
|
|
|
tasks = frappe.get_all("Task", filters=filters,
|
2021-07-01 17:17:34 +05:30
|
|
|
fields=["name", "subject", "status", "modified", "_assign", "exp_end_date", "is_group", "parent_task"],
|
2016-03-23 18:28:50 +05:30
|
|
|
limit_start=start, limit_page_length=10)
|
2021-07-01 17:17:34 +05:30
|
|
|
task_nest = []
|
2016-03-16 18:01:22 +05:30
|
|
|
for task in tasks:
|
2021-07-01 17:17:34 +05:30
|
|
|
if task.is_group:
|
|
|
|
child_tasks = list(filter(lambda x: x.parent_task == task.name, tasks))
|
|
|
|
if len(child_tasks):
|
|
|
|
task.children = child_tasks
|
|
|
|
task_nest.append(task)
|
|
|
|
return list(filter(lambda x: not x.parent_task, tasks))
|
2016-03-16 18:01:22 +05:30
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-03-25 17:19:28 +05:30
|
|
|
def get_task_html(project, start=0, item_status=None):
|
2016-03-23 18:28:50 +05:30
|
|
|
return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
|
2016-03-25 17:19:28 +05:30
|
|
|
{"doc": {
|
|
|
|
"name": project,
|
|
|
|
"project_name": project,
|
|
|
|
"tasks": get_tasks(project, start, item_status=item_status)}
|
|
|
|
}, is_path=True)
|
|
|
|
|
2016-07-05 12:12:39 +05:30
|
|
|
def get_timesheets(project, start=0, search=None):
|
2016-03-16 18:01:22 +05:30
|
|
|
filters = {"project": project}
|
|
|
|
if search:
|
2016-07-05 12:12:39 +05:30
|
|
|
filters["activity_type"] = ("like", "%{0}%".format(search))
|
2016-03-23 18:28:50 +05:30
|
|
|
|
2016-07-05 12:12:39 +05:30
|
|
|
timesheets = frappe.get_all('Timesheet Detail', filters=filters,
|
|
|
|
fields=['project','activity_type','from_time','to_time','parent'],
|
2016-03-23 18:28:50 +05:30
|
|
|
limit_start=start, limit_page_length=10)
|
2016-07-05 12:12:39 +05:30
|
|
|
for timesheet in timesheets:
|
2021-07-01 17:17:34 +05:30
|
|
|
info = frappe.get_all('Timesheet', filters={"name": timesheet.parent},
|
|
|
|
fields=['name','status','modified','modified_by'],
|
2016-07-05 12:12:39 +05:30
|
|
|
limit_start=start, limit_page_length=10)
|
2021-07-01 17:17:34 +05:30
|
|
|
if len(info):
|
|
|
|
timesheet.update(info[0])
|
2016-07-05 12:12:39 +05:30
|
|
|
return timesheets
|
2016-03-16 18:01:22 +05:30
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-07-05 12:12:39 +05:30
|
|
|
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 18:28:50 +05:30
|
|
|
|
2018-09-10 13:40:43 +02: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'])
|