From 360b05f0f5969e4b6a69a64f28a43ab1a26ed9ac Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 2 May 2016 14:13:16 +0530 Subject: [PATCH] [enhancement] activity summary in projects --- erpnext/projects/doctype/project/project.js | 27 ++++++++++++-- erpnext/projects/doctype/project/project.py | 2 ++ .../doctype/project/project_dashboard.html | 36 +++++++++++++------ 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 914839798c..4835287a6a 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -43,11 +43,32 @@ frappe.ui.form.on("Project", { }); } - frm.dashboard.show_heatmap = true; - frm.dashboard.heatmap_message = __('This is based on the Time Logs created against this project'); - frm.dashboard.show_dashboard(); + frm.trigger('show_dashboard'); } + }, + show_dashboard: function(frm) { + frm.dashboard.show_heatmap = true; + frm.dashboard.heatmap_message = __('This is based on the Time Logs created against this project'); + frm.dashboard.show_dashboard(); + if(frm.doc.__onload.activity_summary.length) { + var hours = $.map(frm.doc.__onload.activity_summary, function(d) { return d.total_hours }); + var max_count = Math.max.apply(null, hours); + var sum = hours.reduce(function(a, b) { return a + b; }, 0); + var section = frm.dashboard.add_section( + frappe.render_template('project_dashboard', + { + data: frm.doc.__onload.activity_summary, + max_count: max_count, + sum: sum + })); + + section.on('click', '.time-log-link', function() { + var activity_type = $(this).attr('data-activity_type'); + frappe.set_route('List', 'Time Log', + {'activity_type': activity_type, 'project': frm.doc.name}); + }); + } } }); diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index c5808a209d..cb54a8dfde 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -27,6 +27,8 @@ class Project(Document): }) self.set_onload('links', self.meta.get_links_setup()) + self.set_onload('activity_summary', frappe.db.sql('''select activity_type, sum(hours) as total_hours + from `tabTime Log` where project=%s group by activity_type order by total_hours desc''', self.name, as_dict=True)) def __setup__(self): self.onload() diff --git a/erpnext/projects/doctype/project/project_dashboard.html b/erpnext/projects/doctype/project/project_dashboard.html index efd6861cb8..34a2d04514 100644 --- a/erpnext/projects/doctype/project/project_dashboard.html +++ b/erpnext/projects/doctype/project/project_dashboard.html @@ -1,10 +1,26 @@ -
Tasks
-{% if(project.tasks.length) { %} - {% project.tasks.forEach(function(d) { %} -

{{ d.title }}

- {% }); %} -{% } else { %} -

No Tasks Defined

-{% } %} \ No newline at end of file +
Activity Summary
+
{{ __("Total hours: {0}", [flt(sum, 2) ]) }}
+{% for d in data %} +
+ +
+ + + + + + {{ __("{0} hours", [flt(d.total_hours, 2)]) }} + + + + + + + +
+
+{% endfor %} \ No newline at end of file