From 10dfd4a48faf37b7dab8c386c128f0b8e3b4b296 Mon Sep 17 00:00:00 2001 From: JodeQ Date: Mon, 10 Sep 2018 13:40:43 +0200 Subject: [PATCH] Show project attachments in portal view --- .../doctype/project_user/project_user.json | 56 ++++++++++++++++++- erpnext/templates/pages/projects.html | 26 ++++++++- erpnext/templates/pages/projects.js | 4 ++ erpnext/templates/pages/projects.py | 7 ++- 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/erpnext/projects/doctype/project_user/project_user.json b/erpnext/projects/doctype/project_user/project_user.json index a7cc810a0a..596681676f 100644 --- a/erpnext/projects/doctype/project_user/project_user.json +++ b/erpnext/projects/doctype/project_user/project_user.json @@ -1,5 +1,6 @@ { "allow_copy": 0, + "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, "beta": 0, @@ -11,16 +12,21 @@ "editable_grid": 1, "fields": [ { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "user", "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, + "in_standard_filter": 0, "label": "User", "length": 0, "no_copy": 0, @@ -30,23 +36,30 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 1, "search_index": 1, "set_only_once": 0, + "translatable": 0, "unique": 0 }, { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, + "columns": 0, "fieldname": "welcome_email_sent", "fieldtype": "Check", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, + "in_standard_filter": 0, "label": "Welcome email sent", "length": 0, "no_copy": 0, @@ -55,24 +68,58 @@ "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, + "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, "search_index": 0, "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 1, + "fieldname": "view_attachments", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "View attachments", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, "unique": 0 } ], + "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, "idx": 0, "image_view": 0, "in_create": 0, - "is_submittable": 0, "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2016-07-11 03:28:04.756894", + "modified": "2018-09-09 12:39:38.376816", "modified_by": "Administrator", "module": "Projects", "name": "Project User", @@ -82,7 +129,10 @@ "quick_entry": 0, "read_only": 0, "read_only_onload": 0, + "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", - "track_seen": 0 + "track_changes": 0, + "track_seen": 0, + "track_views": 0 } \ No newline at end of file diff --git a/erpnext/templates/pages/projects.html b/erpnext/templates/pages/projects.html index 765e43fb36..baa2ae62cc 100644 --- a/erpnext/templates/pages/projects.html +++ b/erpnext/templates/pages/projects.html @@ -57,10 +57,34 @@ {% else %}

{{ _("No time sheets") }}

{% endif %} + +{% if doc.attachments %} +
+ +

{{ _("Attachments") }}

+
+ {% for attachment in doc.attachments %} + + {% endfor %} +
+{% endif %} + {% endblock %} diff --git a/erpnext/templates/pages/projects.js b/erpnext/templates/pages/projects.js index 99f0663ee4..b6a2553aed 100644 --- a/erpnext/templates/pages/projects.js +++ b/erpnext/templates/pages/projects.js @@ -36,6 +36,10 @@ frappe.ready(function() { more_items('timeline', false); }); + $(".file-size").each(function() { + $(this).text(frappe.form.formatters.FileSize($(this).text())); + }); + var reload_items = function(item_status, item, $btn) { $.ajax({ diff --git a/erpnext/templates/pages/projects.py b/erpnext/templates/pages/projects.py index d68770dc4d..ddca27455e 100644 --- a/erpnext/templates/pages/projects.py +++ b/erpnext/templates/pages/projects.py @@ -6,7 +6,7 @@ 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") + project_user = frappe.db.get_value("Project User", {"parent": frappe.form_dict.project, "user": frappe.session.user} , ["user", "view_attachments"], as_dict= True) if not project_user or frappe.session.user == 'Guest': raise frappe.PermissionError @@ -22,6 +22,8 @@ def get_context(context): project.timesheets = get_timesheets(project.name, start=0, search=frappe.form_dict.get("search")) + if project_user.view_attachments: + project.attachments = get_attachments(project.name) context.doc = project @@ -92,3 +94,6 @@ 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) +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'])