2020-05-15 07:51:58 +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-19 13:38:30 +00:00
|
|
|
from frappe import _
|
2020-05-15 07:51:58 +00:00
|
|
|
from frappe.utils import nowdate
|
2020-06-11 16:03:43 +00:00
|
|
|
from erpnext.accounts.dashboard_fixtures import _get_fiscal_year
|
|
|
|
from erpnext.buying.dashboard_fixtures import get_company_for_dashboards
|
2020-05-15 07:51:58 +00:00
|
|
|
|
|
|
|
def get_data():
|
2020-06-11 16:03:43 +00:00
|
|
|
fiscal_year = _get_fiscal_year(nowdate())
|
|
|
|
|
|
|
|
if not fiscal_year:
|
|
|
|
return frappe._dict()
|
|
|
|
|
|
|
|
company = frappe.get_doc("Company", get_company_for_dashboards())
|
|
|
|
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-15 07:51:58 +00:00
|
|
|
return frappe._dict({
|
|
|
|
"dashboards": get_dashboards(),
|
2020-06-11 16:03:43 +00:00
|
|
|
"charts": get_charts(company, fiscal_year_name, start_date, end_date),
|
|
|
|
"number_cards": get_number_cards(company, fiscal_year_name, start_date, end_date),
|
2020-05-15 07:51:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
def get_dashboards():
|
|
|
|
return [{
|
|
|
|
"name": "Stock",
|
|
|
|
"dashboard_name": "Stock",
|
|
|
|
"charts": [
|
2020-05-19 13:38:30 +00:00
|
|
|
{ "chart": "Warehouse wise Stock Value", "width": "Full"},
|
|
|
|
{ "chart": "Purchase Receipt Trends", "width": "Half"},
|
|
|
|
{ "chart": "Delivery Trends", "width": "Half"},
|
|
|
|
{ "chart": "Oldest Items", "width": "Half"},
|
|
|
|
{ "chart": "Item Shortage Summary", "width": "Half"}
|
2020-05-15 07:51:58 +00:00
|
|
|
],
|
|
|
|
"cards": [
|
2020-05-19 13:38:30 +00:00
|
|
|
{ "card": "Total Active Items"},
|
|
|
|
{ "card": "Total Warehouses"},
|
|
|
|
{ "card": "Total Stock Value"}
|
2020-05-15 07:51:58 +00:00
|
|
|
]
|
|
|
|
}]
|
|
|
|
|
2020-06-11 16:03:43 +00:00
|
|
|
def get_charts(company, fiscal_year_name, start_date, end_date):
|
2020-05-15 07:51:58 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
2020-05-19 13:38:30 +00:00
|
|
|
"name": "Purchase Receipt Trends",
|
|
|
|
"time_interval": "Monthly",
|
|
|
|
"chart_name": _("Purchase Receipt Trends"),
|
|
|
|
"timespan": "Last Year",
|
|
|
|
"color": "#7b933d",
|
|
|
|
"value_based_on": "base_net_total",
|
|
|
|
"filters_json": json.dumps([["Purchase Receipt", "docstatus", "=", 1]]),
|
|
|
|
"chart_type": "Sum",
|
|
|
|
"timeseries": 1,
|
|
|
|
"based_on": "posting_date",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"document_type": "Purchase Receipt",
|
|
|
|
"type": "Bar",
|
|
|
|
"width": "Half",
|
|
|
|
"is_public": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"name": "Delivery Trends",
|
|
|
|
"time_interval": "Monthly",
|
|
|
|
"chart_name": _("Delivery Trends"),
|
|
|
|
"timespan": "Last Year",
|
|
|
|
"color": "#7b933d",
|
|
|
|
"value_based_on": "base_net_total",
|
|
|
|
"filters_json": json.dumps([["Delivery Note", "docstatus", "=", 1]]),
|
|
|
|
"chart_type": "Sum",
|
|
|
|
"timeseries": 1,
|
|
|
|
"based_on": "posting_date",
|
|
|
|
"owner": "Administrator",
|
|
|
|
"document_type": "Delivery Note",
|
|
|
|
"type": "Bar",
|
|
|
|
"width": "Half",
|
|
|
|
"is_public": 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Warehouse wise Stock Value",
|
|
|
|
"chart_name": _("Warehouse wise Stock Value"),
|
|
|
|
"chart_type": "Custom",
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"filters_json": json.dumps({}),
|
|
|
|
"is_custom": 0,
|
2020-05-15 07:51:58 +00:00
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
2020-05-19 13:38:30 +00:00
|
|
|
"source": "Warehouse wise Stock Value",
|
2020-05-15 07:51:58 +00:00
|
|
|
"type": "Bar"
|
|
|
|
},
|
|
|
|
{
|
2020-05-19 13:38:30 +00:00
|
|
|
"name": "Oldest Items",
|
|
|
|
"chart_name": _("Oldest Items"),
|
2020-05-15 07:51:58 +00:00
|
|
|
"chart_type": "Report",
|
|
|
|
"custom_options": json.dumps({
|
|
|
|
"colors": ["#5e64ff"]
|
|
|
|
}),
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"filters_json": json.dumps({
|
|
|
|
"company": company.name,
|
|
|
|
"to_date": nowdate(),
|
|
|
|
"show_warehouse_wise_stock": 0
|
|
|
|
}),
|
|
|
|
"is_custom": 1,
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"report_name": "Stock Ageing",
|
|
|
|
"type": "Bar"
|
|
|
|
},
|
|
|
|
{
|
2020-05-19 13:38:30 +00:00
|
|
|
"name": "Item Shortage Summary",
|
|
|
|
"chart_name": _("Item Shortage Summary"),
|
2020-05-15 07:51:58 +00:00
|
|
|
"chart_type": "Report",
|
|
|
|
"doctype": "Dashboard Chart",
|
|
|
|
"filters_json": json.dumps({
|
|
|
|
"company": company.name
|
|
|
|
}),
|
|
|
|
"is_custom": 1,
|
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
2020-05-19 13:38:30 +00:00
|
|
|
"report_name": "Item Shortage Report",
|
2020-05-15 07:51:58 +00:00
|
|
|
"type": "Bar"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2020-06-11 16:03:43 +00:00
|
|
|
def get_number_cards(company, fiscal_year_name, start_date, end_date):
|
2020-05-15 07:51:58 +00:00
|
|
|
return [
|
|
|
|
{
|
2020-05-19 13:38:30 +00:00
|
|
|
"name": "Total Active Items",
|
|
|
|
"label": _("Total Active Items"),
|
|
|
|
"function": "Count",
|
2020-05-15 07:51:58 +00:00
|
|
|
"doctype": "Number Card",
|
2020-05-19 13:38:30 +00:00
|
|
|
"document_type": "Item",
|
|
|
|
"filters_json": json.dumps([["Item", "disabled", "=", 0]]),
|
2020-05-15 07:51:58 +00:00
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
2020-05-19 13:38:30 +00:00
|
|
|
"stats_time_interval": "Monthly"
|
2020-05-15 07:51:58 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-19 13:38:30 +00:00
|
|
|
"name": "Total Warehouses",
|
|
|
|
"label": _("Total Warehouses"),
|
2020-05-15 07:51:58 +00:00
|
|
|
"function": "Count",
|
|
|
|
"doctype": "Number Card",
|
2020-05-19 13:38:30 +00:00
|
|
|
"document_type": "Warehouse",
|
|
|
|
"filters_json": json.dumps([["Warehouse", "disabled", "=", 0]]),
|
2020-05-15 07:51:58 +00:00
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
2020-05-19 13:38:30 +00:00
|
|
|
"stats_time_interval": "Monthly"
|
2020-05-15 07:51:58 +00:00
|
|
|
},
|
|
|
|
{
|
2020-05-19 13:38:30 +00:00
|
|
|
"name": "Total Stock Value",
|
|
|
|
"label": _("Total Stock Value"),
|
|
|
|
"function": "Sum",
|
|
|
|
"aggregate_function_based_on": "stock_value",
|
2020-05-15 07:51:58 +00:00
|
|
|
"doctype": "Number Card",
|
2020-05-19 13:38:30 +00:00
|
|
|
"document_type": "Bin",
|
|
|
|
"filters_json": json.dumps([]),
|
2020-05-15 07:51:58 +00:00
|
|
|
"is_public": 1,
|
|
|
|
"owner": "Administrator",
|
|
|
|
"show_percentage_stats": 1,
|
|
|
|
"stats_time_interval": "Daily"
|
|
|
|
}
|
|
|
|
]
|