2020-05-04 14:46:56 +00:00
|
|
|
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
|
|
|
|
# For license information, please see license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-05-04 14:46:56 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-05-04 14:46:56 +00:00
|
|
|
def execute(filters=None):
|
|
|
|
columns = get_columns()
|
|
|
|
data = []
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
data = frappe.db.get_all(
|
|
|
|
"Project",
|
|
|
|
filters=filters,
|
|
|
|
fields=[
|
|
|
|
"name",
|
|
|
|
"status",
|
|
|
|
"percent_complete",
|
|
|
|
"expected_start_date",
|
|
|
|
"expected_end_date",
|
|
|
|
"project_type",
|
|
|
|
],
|
|
|
|
order_by="expected_end_date",
|
|
|
|
)
|
2020-05-04 14:46:56 +00:00
|
|
|
|
|
|
|
for project in data:
|
|
|
|
project["total_tasks"] = frappe.db.count("Task", filters={"project": project.name})
|
2022-03-28 13:22:46 +00:00
|
|
|
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"}
|
|
|
|
)
|
2020-05-04 14:46:56 +00:00
|
|
|
|
|
|
|
chart = get_chart_data(data)
|
|
|
|
report_summary = get_report_summary(data)
|
|
|
|
|
|
|
|
return columns, data, None, chart, report_summary
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-05-04 14:46:56 +00:00
|
|
|
def get_columns():
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
"fieldname": "name",
|
|
|
|
"label": _("Project"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Project",
|
2022-03-28 13:22:46 +00:00
|
|
|
"width": 200,
|
2020-05-04 14:46:56 +00:00
|
|
|
},
|
2020-05-27 06:23:48 +00:00
|
|
|
{
|
|
|
|
"fieldname": "project_type",
|
|
|
|
"label": _("Type"),
|
|
|
|
"fieldtype": "Link",
|
|
|
|
"options": "Project Type",
|
2022-03-28 13:22:46 +00:00
|
|
|
"width": 120,
|
2020-05-04 14:46:56 +00:00
|
|
|
},
|
2022-03-28 13:22:46 +00:00
|
|
|
{"fieldname": "status", "label": _("Status"), "fieldtype": "Data", "width": 120},
|
|
|
|
{"fieldname": "total_tasks", "label": _("Total Tasks"), "fieldtype": "Data", "width": 120},
|
2020-05-04 14:46:56 +00:00
|
|
|
{
|
|
|
|
"fieldname": "completed_tasks",
|
|
|
|
"label": _("Tasks Completed"),
|
|
|
|
"fieldtype": "Data",
|
2022-03-28 13:22:46 +00:00
|
|
|
"width": 120,
|
2020-05-04 14:46:56 +00:00
|
|
|
},
|
2022-03-28 13:22:46 +00:00
|
|
|
{"fieldname": "overdue_tasks", "label": _("Tasks Overdue"), "fieldtype": "Data", "width": 120},
|
|
|
|
{"fieldname": "percent_complete", "label": _("Completion"), "fieldtype": "Data", "width": 120},
|
2020-05-04 14:46:56 +00:00
|
|
|
{
|
|
|
|
"fieldname": "expected_start_date",
|
|
|
|
"label": _("Start Date"),
|
|
|
|
"fieldtype": "Date",
|
2022-03-28 13:22:46 +00:00
|
|
|
"width": 120,
|
2020-05-04 14:46:56 +00:00
|
|
|
},
|
2022-03-28 13:22:46 +00:00
|
|
|
{"fieldname": "expected_end_date", "label": _("End Date"), "fieldtype": "Date", "width": 120},
|
2020-05-04 14:46:56 +00:00
|
|
|
]
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-05-04 14:46:56 +00:00
|
|
|
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": {
|
2022-03-28 13:22:46 +00:00
|
|
|
"labels": labels[:30],
|
|
|
|
"datasets": [
|
|
|
|
{"name": "Overdue", "values": overdue[:30]},
|
|
|
|
{"name": "Completed", "values": completed[:30]},
|
|
|
|
{"name": "Total Tasks", "values": total[:30]},
|
|
|
|
],
|
2020-05-04 14:46:56 +00:00
|
|
|
},
|
|
|
|
"type": "bar",
|
2020-05-05 13:23:29 +00:00
|
|
|
"colors": ["#fc4f51", "#78d6ff", "#7575ff"],
|
2022-03-28 13:22:46 +00:00
|
|
|
"barOptions": {"stacked": True},
|
2020-05-04 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-05-04 14:46:56 +00:00
|
|
|
def get_report_summary(data):
|
2020-05-06 14:56:12 +00:00
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
2021-06-11 13:10:22 +00:00
|
|
|
avg_completion = sum(project.percent_complete for project in data) / len(data)
|
2020-05-04 14:46:56 +00:00
|
|
|
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",
|
2021-04-21 15:04:06 +00:00
|
|
|
"label": _("Average Completion"),
|
2020-05-04 14:46:56 +00:00
|
|
|
"datatype": "Percent",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": total,
|
|
|
|
"indicator": "Blue",
|
2021-04-21 15:04:06 +00:00
|
|
|
"label": _("Total Tasks"),
|
2020-05-04 14:46:56 +00:00
|
|
|
"datatype": "Int",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": completed,
|
|
|
|
"indicator": "Green",
|
2021-04-21 15:04:06 +00:00
|
|
|
"label": _("Completed Tasks"),
|
2020-05-04 14:46:56 +00:00
|
|
|
"datatype": "Int",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"value": total_overdue,
|
|
|
|
"indicator": "Green" if total_overdue == 0 else "Red",
|
2021-04-21 15:04:06 +00:00
|
|
|
"label": _("Overdue Tasks"),
|
2020-05-04 14:46:56 +00:00
|
|
|
"datatype": "Int",
|
2022-03-28 13:22:46 +00:00
|
|
|
},
|
2020-05-04 14:46:56 +00:00
|
|
|
]
|