From 100453c64fdf9bb8d480ea37242b421499bd656e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 4 May 2020 19:32:20 +0530 Subject: [PATCH 01/12] feat: added open count tag --- erpnext/projects/desk_page/projects/projects.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/projects/desk_page/projects/projects.json b/erpnext/projects/desk_page/projects/projects.json index a07cdffcbe..52e502bbed 100644 --- a/erpnext/projects/desk_page/projects/projects.json +++ b/erpnext/projects/desk_page/projects/projects.json @@ -28,7 +28,7 @@ "idx": 0, "is_standard": 1, "label": "Projects", - "modified": "2020-04-01 11:28:51.245756", + "modified": "2020-05-04 18:08:54.363929", "modified_by": "Administrator", "module": "Projects", "name": "Projects", @@ -37,6 +37,7 @@ "pin_to_top": 0, "shortcuts": [ { + "color": "#4d4da8", "format": "{} Assigned", "label": "Task", "link_to": "Task", @@ -44,8 +45,11 @@ "type": "DocType" }, { + "color": "#4d4da8", + "format": "{} Open", "label": "Project", "link_to": "Project", + "stats_filter": "{\n \"status\": \"Open\"\n}", "type": "DocType" }, { From 1607891a3c3bbbbad10c2b6c4509a166df547301 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 4 May 2020 20:16:56 +0530 Subject: [PATCH 02/12] feat: added basic project summary report --- .../report/project_summary/__init__.py | 0 .../report/project_summary/project_summary.js | 23 +++ .../project_summary/project_summary.json | 27 ++++ .../report/project_summary/project_summary.py | 142 ++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 erpnext/projects/report/project_summary/__init__.py create mode 100644 erpnext/projects/report/project_summary/project_summary.js create mode 100644 erpnext/projects/report/project_summary/project_summary.json create mode 100644 erpnext/projects/report/project_summary/project_summary.py diff --git a/erpnext/projects/report/project_summary/__init__.py b/erpnext/projects/report/project_summary/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/projects/report/project_summary/project_summary.js b/erpnext/projects/report/project_summary/project_summary.js new file mode 100644 index 0000000000..15367acd7d --- /dev/null +++ b/erpnext/projects/report/project_summary/project_summary.js @@ -0,0 +1,23 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["Project Summary"] = { + "filters": [ + { + "fieldname": "company", + "label": __("Company"), + "fieldtype": "Link", + "options": "Company", + "default": frappe.defaults.get_user_default("Company"), + "reqd": 1 + }, + { + "fieldname": "status", + "label": __("Status"), + "fieldtype": "Select", + "options": "Open\nComplete\nCancelled", + "default": "Open" + } + ] +}; diff --git a/erpnext/projects/report/project_summary/project_summary.json b/erpnext/projects/report/project_summary/project_summary.json new file mode 100644 index 0000000000..0b18b3e278 --- /dev/null +++ b/erpnext/projects/report/project_summary/project_summary.json @@ -0,0 +1,27 @@ +{ + "add_total_row": 0, + "creation": "2020-05-04 19:31:54.575765", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "idx": 0, + "is_standard": "Yes", + "modified": "2020-05-04 19:32:53.177213", + "modified_by": "Administrator", + "module": "Projects", + "name": "Project Summary", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Project", + "report_name": "Project Summary", + "report_type": "Script Report", + "roles": [ + { + "role": "Projects User" + }, + { + "role": "Projects Manager" + } + ] +} \ No newline at end of file diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py new file mode 100644 index 0000000000..c11c4ca9ff --- /dev/null +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -0,0 +1,142 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe import _ + +def execute(filters=None): + columns = get_columns() + data = [] + + data = frappe.db.get_all("Project", filters=filters, fields=["name", 'status', "percent_complete", "expected_start_date", "expected_end_date"], order_by="expected_end_date") + + for project in data: + project["total_tasks"] = frappe.db.count("Task", filters={"project": project.name}) + project["completed_tasks"] = frappe.db.count("Task", filters={"project": project.name, "status": "Completed"}) + project["overdue_tasks"] = frappe.db.count("Task", filters={"project": project.name, "status": "Overdue"}) + + chart = get_chart_data(data) + report_summary = get_report_summary(data) + + return columns, data, None, chart, report_summary + +def get_columns(): + return [ + { + "fieldname": "name", + "label": _("Project"), + "fieldtype": "Link", + "options": "Project", + "width": 200 + }, + { + "fieldname": "status", + "label": _("Status"), + "fieldtype": "Data", + "width": 120 + }, + { + "fieldname": "total_tasks", + "label": _("Total Tasks"), + "fieldtype": "Data", + "width": 120 + }, + { + "fieldname": "completed_tasks", + "label": _("Tasks Completed"), + "fieldtype": "Data", + "width": 120 + }, + { + "fieldname": "overdue_tasks", + "label": _("Tasks Overdue"), + "fieldtype": "Data", + "width": 120 + }, + { + "fieldname": "percent_complete", + "label": _("Completion"), + "fieldtype": "Data", + "width": 120 + }, + { + "fieldname": "expected_start_date", + "label": _("Start Date"), + "fieldtype": "Date", + "width": 120 + }, + { + "fieldname": "expected_end_date", + "label": _("End Date"), + "fieldtype": "Date", + "width": 120 + }, + ] + +def get_chart_data(data): + labels = [] + total = [] + completed = [] + overdue = [] + + for project in data: + labels.append(project.name) + total.append(project.total_tasks) + completed.append(project.completed_tasks) + overdue.append(project.overdue_tasks) + + return { + "data": { + 'labels': labels, + 'datasets': [ + { + "name": "Total Tasks", + "values": total + }, + { + "name": "Tasks Completed", + "values": completed + }, + { + "name": "Tasks Overdue", + "values": overdue + } + ] + }, + "type": "bar", + "colors": ["#7679fc", "#98d85b", "#fc4f51"] + } + +def get_report_summary(data): + avg_completion = sum([project.percent_complete for project in data]) / len(data) + total = sum([project.total_tasks for project in data]) + total_overdue = sum([project.overdue_tasks for project in data]) + completed = sum([project.completed_tasks for project in data]) + + return [ + { + "value": avg_completion, + "indicator": "Green" if avg_completion > 50 else "Red", + "label": "Average Completion", + "datatype": "Percent", + }, + { + "value": total, + "indicator": "Blue", + "label": "Total Tasks", + "datatype": "Int", + }, + { + "value": completed, + "indicator": "Green", + "label": "Completed Tasks", + "datatype": "Int", + }, + { + "value": total_overdue, + "indicator": "Green" if total_overdue == 0 else "Red", + "label": "Overdue Tasks", + "datatype": "Int", + } + ] From 813bc498689bf53cc7dcb7f9e8bed8737caec730 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 4 May 2020 20:27:26 +0530 Subject: [PATCH 03/12] feat: added Report Summary Chart as fixture --- .../setup_wizard/data/dashboard_charts.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py index bb8c1319bf..ebe183e4c5 100644 --- a/erpnext/setup/setup_wizard/data/dashboard_charts.py +++ b/erpnext/setup/setup_wizard/data/dashboard_charts.py @@ -31,7 +31,14 @@ def get_default_dashboards(): { "chart": "Income" }, { "chart": "Expenses" } ] - } + }, + { + "doctype": "Dashboard", + "dashboard_name": "Project", + "charts": [ + { "chart": "Report Summary", "width": "Full" } + ] + }, ], "Charts": [ { @@ -107,7 +114,18 @@ def get_default_dashboards(): "document_type": "Sales Invoice", "type": "Bar", "width": "Half" - } + }, + { + 'doctype': 'Dashboard Chart', + 'name': 'Project Summary', + 'chart_name': 'Project Summary', + 'chart_type': 'Report', + 'report_name': 'Project Summary', + 'is_public': 1, + 'filters_json': json.dumps({"company": company.name, "status": "Open"}), + 'type': 'Bar', + 'custom_options': '{"type": "bar", "colors": ["#7679fc", "#98d85b", "#fc4f51"], "axisOptions": {"shortenYAxisNumbers": 1}, "tooltipOptions": {}}', + }, ] } From c7f5724fad8259d381b91f62c47fd96f0c70c8ff Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 4 May 2020 20:28:24 +0530 Subject: [PATCH 04/12] feat: added project summary chart to desktop --- erpnext/projects/desk_page/projects/projects.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/projects/desk_page/projects/projects.json b/erpnext/projects/desk_page/projects/projects.json index 52e502bbed..4d4450dbf5 100644 --- a/erpnext/projects/desk_page/projects/projects.json +++ b/erpnext/projects/desk_page/projects/projects.json @@ -17,18 +17,22 @@ } ], "category": "Modules", - "charts": [], + "charts": [ + { + "chart_name": "Project Summary", + "label": "Open Projects" + } + ], "creation": "2020-03-02 15:46:04.874669", "developer_mode_only": 0, "disable_user_customization": 0, "docstatus": 0, "doctype": "Desk Page", "extends_another_page": 0, - "icon": "", "idx": 0, "is_standard": 1, "label": "Projects", - "modified": "2020-05-04 18:08:54.363929", + "modified": "2020-05-04 20:27:51.591365", "modified_by": "Administrator", "module": "Projects", "name": "Projects", From 4ea122662a59952b75144b182115c44c597777be Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 4 May 2020 20:29:51 +0530 Subject: [PATCH 05/12] refactor: less verbose labels for charts --- erpnext/projects/report/project_summary/project_summary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py index c11c4ca9ff..81e63cf70d 100644 --- a/erpnext/projects/report/project_summary/project_summary.py +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -95,11 +95,11 @@ def get_chart_data(data): "values": total }, { - "name": "Tasks Completed", + "name": "Completed", "values": completed }, { - "name": "Tasks Overdue", + "name": "Overdue", "values": overdue } ] From 39fe68880941e79cc8bbf50a717df7326ee3aeea Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 5 May 2020 13:05:38 +0530 Subject: [PATCH 06/12] fix: dashboard chart link --- erpnext/setup/setup_wizard/data/dashboard_charts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py index ebe183e4c5..7edd5e3d4a 100644 --- a/erpnext/setup/setup_wizard/data/dashboard_charts.py +++ b/erpnext/setup/setup_wizard/data/dashboard_charts.py @@ -36,7 +36,7 @@ def get_default_dashboards(): "doctype": "Dashboard", "dashboard_name": "Project", "charts": [ - { "chart": "Report Summary", "width": "Full" } + { "chart": "Project Summary", "width": "Full" } ] }, ], From cc7488a90d579da62b17d8f404d967633bfe36ef Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 5 May 2020 13:05:53 +0530 Subject: [PATCH 07/12] feat: rerun patch to add default dashboards --- erpnext/patches.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5295399695..1f8fabd299 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -630,7 +630,7 @@ execute:frappe.reload_doc('desk', 'doctype', 'dashboard') execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_source') execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart') execute:frappe.reload_doc('desk', 'doctype', 'dashboard_chart_field') -erpnext.patches.v12_0.add_default_dashboards +erpnext.patches.v12_0.add_default_dashboards # 2020-05-05 erpnext.patches.v12_0.remove_bank_remittance_custom_fields erpnext.patches.v12_0.generate_leave_ledger_entries execute:frappe.delete_doc_if_exists("Report", "Loan Repayment") From 5f1240bcc66d1873dc4e84c09df2e449f4033627 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 5 May 2020 18:44:02 +0530 Subject: [PATCH 08/12] feat: updated charts to use stacked layout --- .../projects/report/project_summary/project_summary.py | 10 +++++----- erpnext/setup/setup_wizard/data/dashboard_charts.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py index 81e63cf70d..7f534bf524 100644 --- a/erpnext/projects/report/project_summary/project_summary.py +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -90,10 +90,6 @@ def get_chart_data(data): "data": { 'labels': labels, 'datasets': [ - { - "name": "Total Tasks", - "values": total - }, { "name": "Completed", "values": completed @@ -101,7 +97,11 @@ def get_chart_data(data): { "name": "Overdue", "values": overdue - } + }, + { + "name": "Total Tasks", + "values": total + }, ] }, "type": "bar", diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py index 7edd5e3d4a..ccb23c07e8 100644 --- a/erpnext/setup/setup_wizard/data/dashboard_charts.py +++ b/erpnext/setup/setup_wizard/data/dashboard_charts.py @@ -124,7 +124,7 @@ def get_default_dashboards(): 'is_public': 1, 'filters_json': json.dumps({"company": company.name, "status": "Open"}), 'type': 'Bar', - 'custom_options': '{"type": "bar", "colors": ["#7679fc", "#98d85b", "#fc4f51"], "axisOptions": {"shortenYAxisNumbers": 1}, "tooltipOptions": {}}', + 'custom_options': '{"type": "bar", "colors": ["#98d85b", "#fc4f51", "#7679fc"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}', }, ] } From 945aa08d92185549265c01a6045fba6e15053e8b Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 5 May 2020 18:46:21 +0530 Subject: [PATCH 09/12] feat: show stacked in report --- erpnext/projects/report/project_summary/project_summary.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py index 7f534bf524..dc64176670 100644 --- a/erpnext/projects/report/project_summary/project_summary.py +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -105,7 +105,10 @@ def get_chart_data(data): ] }, "type": "bar", - "colors": ["#7679fc", "#98d85b", "#fc4f51"] + "colors": ["#98d85b", "#fc4f51", "#7679fc"], + "barOptions": { + "stacked": True + } } def get_report_summary(data): From 81f8fbb042eb3554e540a6f25053fb47f8eb052d Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 5 May 2020 18:53:29 +0530 Subject: [PATCH 10/12] feat: update colors --- .../projects/report/project_summary/project_summary.py | 10 +++++----- erpnext/setup/setup_wizard/data/dashboard_charts.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py index dc64176670..66d68bda06 100644 --- a/erpnext/projects/report/project_summary/project_summary.py +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -90,14 +90,14 @@ def get_chart_data(data): "data": { 'labels': labels, 'datasets': [ - { - "name": "Completed", - "values": completed - }, { "name": "Overdue", "values": overdue }, + { + "name": "Completed", + "values": completed + }, { "name": "Total Tasks", "values": total @@ -105,7 +105,7 @@ def get_chart_data(data): ] }, "type": "bar", - "colors": ["#98d85b", "#fc4f51", "#7679fc"], + "colors": ["#fc4f51", "#78d6ff", "#7575ff"], "barOptions": { "stacked": True } diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py index d54462e1be..9ce64eb9d9 100644 --- a/erpnext/setup/setup_wizard/data/dashboard_charts.py +++ b/erpnext/setup/setup_wizard/data/dashboard_charts.py @@ -125,7 +125,7 @@ def get_default_dashboards(): 'is_public': 1, 'filters_json': json.dumps({"company": company.name, "status": "Open"}), 'type': 'Bar', - 'custom_options': '{"type": "bar", "colors": ["#98d85b", "#fc4f51", "#7679fc"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}', + 'custom_options': '{"type": "bar", "colors": ["#fc4f51", "#78d6ff", "#7575ff"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}', }, { "doctype": "Dashboard Chart", From 20a1d375f3898cf510b0e0bbbdf9e2e3ff754f93 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 6 May 2020 20:26:00 +0530 Subject: [PATCH 11/12] feat: add fixture for project dashboards --- erpnext/projects/dashboard_fixtures.py | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 erpnext/projects/dashboard_fixtures.py diff --git a/erpnext/projects/dashboard_fixtures.py b/erpnext/projects/dashboard_fixtures.py new file mode 100644 index 0000000000..63b3893b76 --- /dev/null +++ b/erpnext/projects/dashboard_fixtures.py @@ -0,0 +1,48 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe +import json + +def get_company_for_dashboards(): + company = frappe.defaults.get_defaults().company + if company: + return company + else: + company_list = frappe.get_list("Company") + if company_list: + return company_list[0].name + return None + +def get_data(): + return frappe._dict({ + "dashboards": get_dashboards(), + "charts": get_charts(), + }) + +def get_dashboards(): + return [{ + "doctype": "Dashboard", + "name": "Project", + "dashboard_name": "Project", + "charts": [ + { "chart": "Project Summary", "width": "Full" } + ] + }] + +def get_charts(): + company = frappe.get_doc("Company", get_company_for_dashboards()) + + return [ + { + 'doctype': 'Dashboard Chart', + 'name': 'Project Summary', + 'chart_name': 'Project Summary', + 'chart_type': 'Report', + 'report_name': 'Project Summary', + 'is_public': 1, + 'filters_json': json.dumps({"company": company.name, "status": "Open"}), + 'type': 'Bar', + 'custom_options': '{"type": "bar", "colors": ["#fc4f51", "#78d6ff", "#7575ff"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}', + } + ] \ No newline at end of file From 318affedb8d63fc37544c59ca79caba581f8efb3 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 6 May 2020 20:26:12 +0530 Subject: [PATCH 12/12] fix: divide by zero error --- erpnext/projects/report/project_summary/project_summary.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/projects/report/project_summary/project_summary.py b/erpnext/projects/report/project_summary/project_summary.py index 66d68bda06..a20d7f25a3 100644 --- a/erpnext/projects/report/project_summary/project_summary.py +++ b/erpnext/projects/report/project_summary/project_summary.py @@ -112,6 +112,9 @@ def get_chart_data(data): } def get_report_summary(data): + if not data: + return None + avg_completion = sum([project.percent_complete for project in data]) / len(data) total = sum([project.total_tasks for project in data]) total_overdue = sum([project.overdue_tasks for project in data])