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 @@ -
No Tasks Defined
-{% } %} \ No newline at end of file +