Merge branch 'project-refresh' of https://github.com/scmmishra/erpnext into scmmishra-project-refresh

This commit is contained in:
Nabin Hait 2020-05-19 21:03:39 +05:30
commit 0b10c6a1bc
7 changed files with 408 additions and 3 deletions

View File

@ -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 }}',
}
]

View File

@ -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-04-01 11:28:51.245756",
"modified": "2020-05-04 20:27:51.591365",
"modified_by": "Administrator",
"module": "Projects",
"name": "Projects",
@ -37,6 +41,7 @@
"pin_to_top": 0,
"shortcuts": [
{
"color": "#4d4da8",
"format": "{} Assigned",
"label": "Task",
"link_to": "Task",
@ -44,8 +49,11 @@
"type": "DocType"
},
{
"color": "#4d4da8",
"format": "{} Open",
"label": "Project",
"link_to": "Project",
"stats_filter": "{\n \"status\": \"Open\"\n}",
"type": "DocType"
},
{

View File

@ -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"
}
]
};

View File

@ -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"
}
]
}

View File

@ -0,0 +1,148 @@
# 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": "Overdue",
"values": overdue
},
{
"name": "Completed",
"values": completed
},
{
"name": "Total Tasks",
"values": total
},
]
},
"type": "bar",
"colors": ["#fc4f51", "#78d6ff", "#7575ff"],
"barOptions": {
"stacked": True
}
}
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])
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",
}
]

View File

@ -0,0 +1,151 @@
from __future__ import unicode_literals
from frappe import _
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_default_dashboards():
company = frappe.get_doc("Company", get_company_for_dashboards())
income_account = company.default_income_account or get_account("Income Account", company.name)
expense_account = company.default_expense_account or get_account("Expense Account", company.name)
bank_account = company.default_bank_account or get_account("Bank", company.name)
return {
"Dashboards": [
{
"doctype": "Dashboard",
"dashboard_name": "Accounts",
"charts": [
{ "chart": "Outgoing Bills (Sales Invoice)" },
{ "chart": "Incoming Bills (Purchase Invoice)" },
{ "chart": "Bank Balance" },
{ "chart": "Income" },
{ "chart": "Expenses" },
{ "chart": "Patient Appointments" }
]
},
{
"doctype": "Dashboard",
"dashboard_name": "Project",
"charts": [
{ "chart": "Project Summary", "width": "Full" }
]
},
],
"Charts": [
{
"doctype": "Dashboard Chart",
"time_interval": "Quarterly",
"chart_name": "Income",
"timespan": "Last Year",
"color": None,
"filters_json": json.dumps({"company": company.name, "account": income_account}),
"source": "Account Balance Timeline",
"chart_type": "Custom",
"timeseries": 1,
"owner": "Administrator",
"type": "Line",
"width": "Half"
},
{
"doctype": "Dashboard Chart",
"time_interval": "Quarterly",
"chart_name": "Expenses",
"timespan": "Last Year",
"color": None,
"filters_json": json.dumps({"company": company.name, "account": expense_account}),
"source": "Account Balance Timeline",
"chart_type": "Custom",
"timeseries": 1,
"owner": "Administrator",
"type": "Line",
"width": "Half"
},
{
"doctype": "Dashboard Chart",
"time_interval": "Quarterly",
"chart_name": "Bank Balance",
"timespan": "Last Year",
"color": "#ffb868",
"filters_json": json.dumps({"company": company.name, "account": bank_account}),
"source": "Account Balance Timeline",
"chart_type": "Custom",
"timeseries": 1,
"owner": "Administrator",
"type": "Line",
"width": "Half"
},
{
"doctype": "Dashboard Chart",
"time_interval": "Monthly",
"chart_name": "Incoming Bills (Purchase Invoice)",
"timespan": "Last Year",
"color": "#a83333",
"value_based_on": "base_grand_total",
"filters_json": json.dumps({}),
"chart_type": "Sum",
"timeseries": 1,
"based_on": "posting_date",
"owner": "Administrator",
"document_type": "Purchase Invoice",
"type": "Bar",
"width": "Half"
},
{
"doctype": "Dashboard Chart",
"time_interval": "Monthly",
"chart_name": "Outgoing Bills (Sales Invoice)",
"timespan": "Last Year",
"color": "#7b933d",
"value_based_on": "base_grand_total",
"filters_json": json.dumps({}),
"chart_type": "Sum",
"timeseries": 1,
"based_on": "posting_date",
"owner": "Administrator",
"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": ["#fc4f51", "#78d6ff", "#7575ff"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}',
},
{
"doctype": "Dashboard Chart",
"time_interval": "Daily",
"chart_name": "Patient Appointments",
"timespan": "Last Month",
"color": "#77ecca",
"filters_json": json.dumps({}),
"chart_type": "Count",
"timeseries": 1,
"based_on": "appointment_datetime",
"owner": "Administrator",
"document_type": "Patient Appointment",
"type": "Line",
"width": "Half"
}
]
}
def get_account(account_type, company):
accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
if accounts:
return accounts[0].name