Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 4 | |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 5 | import frappe |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 6 | |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 7 | |
| 8 | def get_context(context): |
JodeQ | 10dfd4a | 2018-09-10 13:40:43 +0200 | [diff] [blame] | 9 | project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , ["user", "view_attachments"], as_dict= True) |
Faris Ansari | 82770d9 | 2019-07-16 09:40:09 +0530 | [diff] [blame] | 10 | if frappe.session.user != 'Administrator' and (not project_user or frappe.session.user == 'Guest'): |
Kanchan Chauhan | a4ff5d3 | 2016-04-08 23:22:04 +0530 | [diff] [blame] | 11 | raise frappe.PermissionError |
Faris Ansari | 82770d9 | 2019-07-16 09:40:09 +0530 | [diff] [blame] | 12 | |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 13 | context.no_cache = 1 |
Kanchan Chauhan | 11638ba | 2016-04-20 16:20:49 +0530 | [diff] [blame] | 14 | context.show_sidebar = True |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 15 | project = frappe.get_doc('Project', frappe.form_dict.project) |
| 16 | |
| 17 | project.has_permission('read') |
Faris Ansari | 82770d9 | 2019-07-16 09:40:09 +0530 | [diff] [blame] | 18 | |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 19 | project.tasks = get_tasks(project.name, start=0, item_status='open', |
Kanchan Chauhan | 239b351 | 2016-05-02 11:43:44 +0530 | [diff] [blame] | 20 | search=frappe.form_dict.get("search")) |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 21 | |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 22 | project.timesheets = get_timesheets(project.name, start=0, |
| 23 | search=frappe.form_dict.get("search")) |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 24 | |
Faris Ansari | 82770d9 | 2019-07-16 09:40:09 +0530 | [diff] [blame] | 25 | if project_user and project_user.view_attachments: |
JodeQ | 10dfd4a | 2018-09-10 13:40:43 +0200 | [diff] [blame] | 26 | project.attachments = get_attachments(project.name) |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 27 | |
| 28 | context.doc = project |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 29 | |
| 30 | |
Kanchan Chauhan | 2ad801c | 2016-03-22 16:00:41 +0530 | [diff] [blame] | 31 | def get_tasks(project, start=0, search=None, item_status=None): |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 32 | filters = {"project": project} |
| 33 | if search: |
| 34 | filters["subject"] = ("like", "%{0}%".format(search)) |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 35 | tasks = frappe.get_all("Task", filters=filters, |
Jannat Patel | 5a42511 | 2021-07-01 17:17:34 +0530 | [diff] [blame] | 36 | fields=["name", "subject", "status", "modified", "_assign", "exp_end_date", "is_group", "parent_task"], |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 37 | limit_start=start, limit_page_length=10) |
Jannat Patel | 5a42511 | 2021-07-01 17:17:34 +0530 | [diff] [blame] | 38 | task_nest = [] |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 39 | for task in tasks: |
Jannat Patel | 5a42511 | 2021-07-01 17:17:34 +0530 | [diff] [blame] | 40 | if task.is_group: |
| 41 | child_tasks = list(filter(lambda x: x.parent_task == task.name, tasks)) |
| 42 | if len(child_tasks): |
| 43 | task.children = child_tasks |
| 44 | task_nest.append(task) |
| 45 | return list(filter(lambda x: not x.parent_task, tasks)) |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 46 | |
| 47 | @frappe.whitelist() |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 48 | def get_task_html(project, start=0, item_status=None): |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 49 | return frappe.render_template("erpnext/templates/includes/projects/project_tasks.html", |
Rushabh Mehta | c20c536 | 2016-03-25 17:19:28 +0530 | [diff] [blame] | 50 | {"doc": { |
| 51 | "name": project, |
| 52 | "project_name": project, |
| 53 | "tasks": get_tasks(project, start, item_status=item_status)} |
| 54 | }, is_path=True) |
| 55 | |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 56 | def get_timesheets(project, start=0, search=None): |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 57 | filters = {"project": project} |
| 58 | if search: |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 59 | filters["activity_type"] = ("like", "%{0}%".format(search)) |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 60 | |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 61 | timesheets = frappe.get_all('Timesheet Detail', filters=filters, |
| 62 | fields=['project','activity_type','from_time','to_time','parent'], |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 63 | limit_start=start, limit_page_length=10) |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 64 | for timesheet in timesheets: |
Jannat Patel | 5a42511 | 2021-07-01 17:17:34 +0530 | [diff] [blame] | 65 | info = frappe.get_all('Timesheet', filters={"name": timesheet.parent}, |
| 66 | fields=['name','status','modified','modified_by'], |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 67 | limit_start=start, limit_page_length=10) |
Jannat Patel | 5a42511 | 2021-07-01 17:17:34 +0530 | [diff] [blame] | 68 | if len(info): |
| 69 | timesheet.update(info[0]) |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 70 | return timesheets |
Kanchan Chauhan | b3fe6a4 | 2016-03-16 18:01:22 +0530 | [diff] [blame] | 71 | |
| 72 | @frappe.whitelist() |
Kanchan Chauhan | 6d76359c | 2016-07-05 12:12:39 +0530 | [diff] [blame] | 73 | def get_timesheet_html(project, start=0): |
| 74 | return frappe.render_template("erpnext/templates/includes/projects/project_timesheets.html", |
| 75 | {"doc": {"timesheets": get_timesheets(project, start)}}, is_path=True) |
Rushabh Mehta | b2269dd | 2016-03-23 18:28:50 +0530 | [diff] [blame] | 76 | |
JodeQ | 10dfd4a | 2018-09-10 13:40:43 +0200 | [diff] [blame] | 77 | def get_attachments(project): |
| 78 | return frappe.get_all('File', filters= {"attached_to_name": project, "attached_to_doctype": 'Project', "is_private":0}, |
| 79 | fields=['file_name','file_url', 'file_size']) |