2020-05-12 07:46:05 +00:00
|
|
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
import json
|
2020-05-15 18:07:48 +00:00
|
|
|
from frappe.utils import nowdate
|
|
|
|
from erpnext.accounts.utils import get_fiscal_year
|
2020-05-12 07:46:05 +00:00
|
|
|
|
|
|
|
def get_data():
|
|
|
|
return frappe._dict({
|
|
|
|
"dashboards": get_dashboards(),
|
|
|
|
"charts": get_charts(),
|
|
|
|
"number_cards": get_number_cards(),
|
|
|
|
})
|
|
|
|
|
2020-05-12 12:05:17 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
company = frappe.get_doc("Company", get_company_for_dashboards())
|
2020-05-15 18:07:48 +00:00
|
|
|
fiscal_year = get_fiscal_year(nowdate(), as_dict=1)
|
|
|
|
fiscal_year_name = fiscal_year.get("name")
|
|
|
|
start_date = str(fiscal_year.get("year_start_date"))
|
|
|
|
end_date = str(fiscal_year.get("year_end_date"))
|
2020-05-12 12:05:17 +00:00
|
|
|
|
2020-05-12 07:46:05 +00:00
|
|
|
def get_dashboards():
|
|
|
|
return [{
|
2020-05-12 12:05:17 +00:00
|
|
|
"name": "Buying",
|
|
|
|
"dashboard_name": "Buying",
|
2020-05-12 07:46:05 +00:00
|
|
|
"charts": [
|
2020-05-19 11:32:47 +00:00
|
|
|
{ "chart": "Purchase Order Trends", "width": "Full"},
|
2020-05-15 18:07:48 +00:00
|
|
|
{ "chart": "Material Request Analysis", "width": "Half"},
|
2020-05-12 12:05:17 +00:00
|
|
|
{ "chart": "Purchase Order Analysis", "width": "Half"},
|
2020-05-19 11:32:47 +00:00
|
|
|
{ "chart": "Top Suppliers", "width": "Full"}
|
2020-05-15 18:07:48 +00:00
|
|
|
],
|
|
|
|
"cards": [
|
|
|
|
{ "card": "Purchase Orders to Receive"},
|
|
|
|
{ "card": "Purchase Order Expenses"},
|
|
|
|
{ "card": "Active Suppliers"},
|
|
|
|
{ "card": "Active Supplier Quotations"}
|
2020-05-12 07:46:05 +00:00
|
|
|
]
|
|
|
|
}]
|
|
|
|
|
|
|
|
def get_charts():
|
2020-05-12 12:05:17 +00:00
|
|
|
return [
|
|
|
|
{
|
2020-05-15 18:07:48 +00:00
|
|
|
"name": "Purchase Order Analysis",
|
|
|
|
"chart_name": "Purchase Order Analysis",
|
|
|
|
"chart_type": "Report",
|
|
|
|
"custom_options": json.dumps({
|
|
|
|
"type": "donut",
|
|
|
|
"height": 300,
|
|
|
|
"axisOptions": {"shortenYAxisNumbers": 1}
|
|
|
|
}),
|
2020-05-12 12:05:17 +00:00
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"filters_json": json.dumps({
|
|
|
|
"company": company.name,
|
2020-05-15 18:07:48 +00:00
|
|
|
"from_date": start_date,
|
|
|
|
"to_date": end_date
|
|
|
|
}),
|
|
|
|
"is_custom": 1,
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"report_name": "Purchase Order Analysis",
|
|
|
|
"type": "Donut"
|
2020-05-12 12:05:17 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-15 18:07:48 +00:00
|
|
|
"name": "Material Request Analysis",
|
|
|
|
"chart_name": "Material Request Analysis",
|
|
|
|
"chart_type": "Group By",
|
|
|
|
"custom_options": json.dumps({"height": 300}),
|
2020-05-12 12:05:17 +00:00
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"document_type": "Material Request",
|
2020-05-15 18:07:48 +00:00
|
|
|
"filters_json": json.dumps(
|
|
|
|
[["Material Request", "status", "not in", ["Draft", "Cancelled", "Stopped", None], False],
|
|
|
|
["Material Request", "material_request_type", "=", "Purchase", False],
|
2020-05-19 11:32:47 +00:00
|
|
|
["Material Request", "company", "=", company.name, False],
|
|
|
|
["Material Request", "transaction_date", "Between", [start_date,end_date], False]]
|
2020-05-15 18:07:48 +00:00
|
|
|
),
|
2020-05-12 12:05:17 +00:00
|
|
|
"group_by_based_on": "status",
|
|
|
|
"group_by_type": "Count",
|
2020-05-15 18:07:48 +00:00
|
|
|
"is_custom": 0,
|
|
|
|
"is_public": 1,
|
|
|
|
"number_of_groups": 0,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"type": "Donut"
|
2020-05-12 12:05:17 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-15 18:07:48 +00:00
|
|
|
"name": "Purchase Order Trends",
|
|
|
|
"chart_name": "Purchase Order Trends",
|
|
|
|
"chart_type": "Report",
|
|
|
|
"custom_options": json.dumps({
|
|
|
|
"type": "line",
|
|
|
|
"axisOptions": {"shortenYAxisNumbers": 1},
|
2020-05-19 11:32:47 +00:00
|
|
|
"tooltipOptions": {},
|
|
|
|
"lineOptions": {
|
|
|
|
"regionFill": 1
|
|
|
|
}
|
2020-05-15 18:07:48 +00:00
|
|
|
}),
|
2020-05-12 12:05:17 +00:00
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"filters_json": json.dumps({
|
|
|
|
"company": company.name,
|
2020-05-15 18:07:48 +00:00
|
|
|
"period": "Monthly",
|
|
|
|
"fiscal_year": fiscal_year_name,
|
|
|
|
"period_based_on": "posting_date",
|
|
|
|
"based_on": "Item"
|
2020-05-12 12:05:17 +00:00
|
|
|
}),
|
|
|
|
"is_custom": 1,
|
2020-05-15 18:07:48 +00:00
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"report_name": "Purchase Order Trends",
|
|
|
|
"type": "Line"
|
2020-05-12 12:05:17 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-15 18:07:48 +00:00
|
|
|
"name": "Top Suppliers",
|
|
|
|
"chart_name": "Top Suppliers",
|
|
|
|
"chart_type": "Report",
|
2020-05-12 12:05:17 +00:00
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"filters_json": json.dumps({
|
|
|
|
"company": company.name,
|
2020-05-15 18:07:48 +00:00
|
|
|
"period": "Monthly",
|
|
|
|
"fiscal_year": fiscal_year_name,
|
|
|
|
"period_based_on": "posting_date",
|
|
|
|
"based_on": "Supplier"
|
2020-05-12 12:05:17 +00:00
|
|
|
}),
|
|
|
|
"is_custom": 1,
|
2020-05-15 18:07:48 +00:00
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"report_name": "Purchase Receipt Trends",
|
|
|
|
"type": "Bar"
|
2020-05-12 12:05:17 +00:00
|
|
|
}
|
|
|
|
]
|
2020-05-12 07:46:05 +00:00
|
|
|
|
|
|
|
def get_number_cards():
|
2020-05-15 18:07:48 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"name": "Purchase Order Expenses",
|
|
|
|
"aggregate_function_based_on": "base_grand_total",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Purchase Order",
|
|
|
|
"filters_json": json.dumps(
|
|
|
|
[["Purchase Order", "transaction_date", "Between", [start_date,end_date], False],
|
|
|
|
["Purchase Order", "status", "not in", ["Draft","On Hold","Cancelled","Closed", None], False],
|
2020-05-19 11:32:47 +00:00
|
|
|
["Purchase Order", "company", "=", company.name, False],
|
|
|
|
["Purchase Order", "transaction_date", "Between", [start_date,end_date], False]]
|
2020-05-15 18:07:48 +00:00
|
|
|
),
|
|
|
|
"function": "Sum",
|
|
|
|
"is_public": 1,
|
|
|
|
"label": "Purchase Order Expenses",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Monthly"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Purchase Orders to Receive",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Purchase Order",
|
|
|
|
"filters_json": json.dumps(
|
|
|
|
[["Purchase Order", "status", "in", ["To Receive and Bill", "To Receive", None], False],
|
2020-05-19 11:32:47 +00:00
|
|
|
["Purchase Order", "company", "=", company.name, False],
|
|
|
|
["Purchase Order", "transaction_date", "Between", [start_date,end_date], False]]
|
2020-05-15 18:07:48 +00:00
|
|
|
),
|
|
|
|
"function": "Count",
|
|
|
|
"is_public": 1,
|
|
|
|
"label": "Purchase Orders to Receive",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Weekly"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Active Suppliers",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Supplier",
|
|
|
|
"filters_json": json.dumps([["Supplier", "disabled", "=", "0"]]),
|
|
|
|
"function": "Count",
|
|
|
|
"is_public": 1,
|
|
|
|
"label": "Active Suppliers",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Monthly"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Active Supplier Quotations",
|
|
|
|
"doctype": "Number Card",
|
|
|
|
"document_type": "Supplier Quotation",
|
|
|
|
"filters_json": json.dumps([["Supplier Quotation", "status", "=", "Submitted", False]]),
|
|
|
|
"function": "Count",
|
|
|
|
"is_public": 1,
|
|
|
|
"label": "Active Supplier Quotations",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Monthly"
|
|
|
|
}
|
|
|
|
]
|