blob: d68770dc4def8cbe0af26e5630cbf995b0f12b85 [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
Rushabh Mehtab2269dd2016-03-23 18:28:50 +05306import json
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +05307
8def get_context(context):
Kanchan Chauhana4ff5d32016-04-08 23:22:04 +05309 project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , "user")
10 if not project_user or frappe.session.user == 'Guest':
11 raise frappe.PermissionError
12
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053013 context.no_cache = 1
Kanchan Chauhan11638ba2016-04-20 16:20:49 +053014 context.show_sidebar = True
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053015 project = frappe.get_doc('Project', frappe.form_dict.project)
16
17 project.has_permission('read')
Kanchan Chauhanb566d422016-03-29 11:21:42 +053018
Rushabh Mehtac20c5362016-03-25 17:19:28 +053019 project.tasks = get_tasks(project.name, start=0, item_status='open',
Kanchan Chauhan239b3512016-05-02 11:43:44 +053020 search=frappe.form_dict.get("search"))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053021
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053022 project.timesheets = get_timesheets(project.name, start=0,
23 search=frappe.form_dict.get("search"))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053024
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053025
26 context.doc = project
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053027
28
Kanchan Chauhan2ad801c2016-03-22 16:00:41 +053029def get_tasks(project, start=0, search=None, item_status=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053030 filters = {"project": project}
31 if search:
32 filters["subject"] = ("like", "%{0}%".format(search))
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053033 # if item_status:
34# filters["status"] = item_status
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053035 tasks = frappe.get_all("Task", filters=filters,
Kanchan Chauhanb566d422016-03-29 11:21:42 +053036 fields=["name", "subject", "status", "_seen", "_comments", "modified", "description"],
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053037 limit_start=start, limit_page_length=10)
38
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053039 for task in tasks:
40 task.todo = frappe.get_all('ToDo',filters={'reference_name':task.name, 'reference_type':'Task'},
41 fields=["assigned_by", "owner", "modified", "modified_by"])
Rushabh Mehtac20c5362016-03-25 17:19:28 +053042
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053043 if task.todo:
44 task.todo=task.todo[0]
45 task.todo.user_image = frappe.db.get_value('User', task.todo.owner, 'user_image')
Rushabh Mehtac20c5362016-03-25 17:19:28 +053046
Kanchan Chauhanb566d422016-03-29 11:21:42 +053047
48 task.comment_count = len(json.loads(task._comments or "[]"))
Rushabh Mehtac20c5362016-03-25 17:19:28 +053049
50 task.css_seen = ''
51 if task._seen:
52 if frappe.session.user in json.loads(task._seen):
53 task.css_seen = 'seen'
54
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053055 return tasks
56
57@frappe.whitelist()
Rushabh Mehtac20c5362016-03-25 17:19:28 +053058def get_task_html(project, start=0, item_status=None):
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053059 return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html",
Rushabh Mehtac20c5362016-03-25 17:19:28 +053060 {"doc": {
61 "name": project,
62 "project_name": project,
63 "tasks": get_tasks(project, start, item_status=item_status)}
64 }, is_path=True)
65
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053066def get_timesheets(project, start=0, search=None):
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053067 filters = {"project": project}
68 if search:
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053069 filters["activity_type"] = ("like", "%{0}%".format(search))
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053070
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053071 timesheets = frappe.get_all('Timesheet Detail', filters=filters,
72 fields=['project','activity_type','from_time','to_time','parent'],
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053073 limit_start=start, limit_page_length=10)
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053074 for timesheet in timesheets:
75 timesheet.infos = frappe.get_all('Timesheet', filters={"name": timesheet.parent},
76 fields=['name','_comments','_seen','status','modified','modified_by'],
77 limit_start=start, limit_page_length=10)
Kanchan Chauhanb566d422016-03-29 11:21:42 +053078
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053079 for timesheet.info in timesheet.infos:
80 timesheet.info.user_image = frappe.db.get_value('User', timesheet.info.modified_by, 'user_image')
81
82 timesheet.info.comment_count = len(json.loads(timesheet.info._comments or "[]"))
83
84 timesheet.info.css_seen = ''
85 if timesheet.info._seen:
86 if frappe.session.user in json.loads(timesheet.info._seen):
87 timesheet.info.css_seen = 'seen'
88 return timesheets
Kanchan Chauhanb3fe6a42016-03-16 18:01:22 +053089
90@frappe.whitelist()
Kanchan Chauhan6d76359c2016-07-05 12:12:39 +053091def get_timesheet_html(project, start=0):
92 return frappe.render_template("erpnext/templates/includes/projects/project_timesheets.html",
93 {"doc": {"timesheets": get_timesheets(project, start)}}, is_path=True)
Rushabh Mehtab2269dd2016-03-23 18:28:50 +053094