From a4ff5d3195e3c0c4f85a32061a53c961bc2390d1 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Fri, 8 Apr 2016 23:22:04 +0530 Subject: [PATCH] Collaborate PM permission fixes and daily tme log fix --- erpnext/projects/doctype/task/task.py | 10 +++++++++- erpnext/projects/doctype/time_log/time_log.py | 5 +++++ .../daily_time_log_summary.py | 17 ++++++++++++++++- erpnext/templates/pages/projects.py | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 15c98f4c40..392f1406c4 100644 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -101,6 +101,11 @@ class Task(Document): task.exp_end_date = add_days(task.exp_start_date, task_duration) task.flags.ignore_recursion_check = True task.save() + + def has_webform_permission(doc): + project_user = frappe.db.get_value("Project User", {"parent": doc.project, "user":frappe.session.user} , "user") + if project_user: + return True @frappe.whitelist() def get_events(start, end, filters=None): @@ -134,7 +139,7 @@ def get_project(doctype, txt, searchfield, start, page_len, filters): order by name limit %(start)s, %(page_len)s """ % {'key': searchfield, 'txt': "%%%s%%" % frappe.db.escape(txt), 'mcond':get_match_cond(doctype), - 'start': start, 'page_len': page_len}) + 'start': start, 'page_len': page_len}) @frappe.whitelist() @@ -150,3 +155,6 @@ def set_tasks_as_overdue(): where exp_end_date is not null and exp_end_date < CURDATE() and `status` not in ('Closed', 'Cancelled')""") + + + diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py index 1d523d9847..e2641ebb02 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -247,6 +247,11 @@ class TimeLog(Document): elif self.project: frappe.get_doc("Project", self.project).update_project() + + def has_webform_permission(doc): + project_user = frappe.db.get_value("Project User", {"parent": doc.project, "user":frappe.session.user} , "user") + if project_user: + return True @frappe.whitelist() diff --git a/erpnext/projects/report/daily_time_log_summary/daily_time_log_summary.py b/erpnext/projects/report/daily_time_log_summary/daily_time_log_summary.py index 74436a3923..028fd7749e 100644 --- a/erpnext/projects/report/daily_time_log_summary/daily_time_log_summary.py +++ b/erpnext/projects/report/daily_time_log_summary/daily_time_log_summary.py @@ -18,6 +18,7 @@ def execute(filters=None): _("Task Subject") + "::180", _("Project") + ":Link/Project:120", _("Status") + "::70"] user_map = get_user_map() + employee_map = get_employee_map() task_map = get_task_map() conditions = build_conditions(filters) @@ -30,12 +31,16 @@ def execute(filters=None): data = [] total_hours = total_employee_hours = count = 0 for tl in time_logs: + if tl.employee: + employee=employee_map[tl.employee] + else: + employee=user_map[tl.owner] if tl.owner not in users: users.append(tl.owner) data.append(["", "", "", "Total", total_employee_hours, "", "", "", "", ""]) total_employee_hours = 0 - data.append([tl.name, user_map[tl.owner], tl.from_time, tl.to_time, tl.hours, + data.append([tl.name, employee, tl.from_time, tl.to_time, tl.hours, tl.activity_type, tl.task, task_map.get(tl.task), tl.project, tl.status]) count += 1 @@ -59,6 +64,16 @@ def get_user_map(): user_map.setdefault(p.name, []).append(p.fullname) return user_map + +def get_employee_map(): + employees = frappe.db.sql("""select name, + employee_name as fullname + from tabEmployee""", as_dict=1) + employee_map = {} + for p in employees: + employee_map.setdefault(p.name, []).append(p.fullname) + + return employee_map def get_task_map(): tasks = frappe.db.sql("""select name, subject from tabTask""", as_dict=1) diff --git a/erpnext/templates/pages/projects.py b/erpnext/templates/pages/projects.py index 86f064c32e..218f63c6da 100644 --- a/erpnext/templates/pages/projects.py +++ b/erpnext/templates/pages/projects.py @@ -6,6 +6,10 @@ import frappe import json def get_context(context): + project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , "user") + if not project_user or frappe.session.user == 'Guest': + raise frappe.PermissionError + context.no_cache = 1 project = frappe.get_doc('Project', frappe.form_dict.project)