brotherton-erpnext/erpnext/assets/dashboard_fixtures.py

179 lines
4.7 KiB
Python
Raw Normal View History

2020-05-08 11:09:17 +00:00
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
import json
from frappe.utils import nowdate, add_months, get_date_str
from frappe import _
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-08 11:09:17 +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()
2020-06-12 09:59:40 +00:00
year_start_date = get_date_str(fiscal_year.get('year_start_date'))
year_end_date = get_date_str(fiscal_year.get('year_end_date'))
2020-06-11 16:03:43 +00:00
2020-05-08 11:09:17 +00:00
return frappe._dict({
"dashboards": get_dashboards(),
2020-06-11 16:03:43 +00:00
"charts": get_charts(fiscal_year, year_start_date, year_end_date),
"number_cards": get_number_cards(fiscal_year, year_start_date, year_end_date),
2020-05-08 11:09:17 +00:00
})
def get_dashboards():
return [{
"name": "Asset",
"dashboard_name": "Asset",
"charts": [
{ "chart": "Asset Value Analytics", "width": "Full" },
{ "chart": "Category-wise Asset Value", "width": "Half" },
{ "chart": "Location-wise Asset Value", "width": "Half" },
],
"cards": [
{"card": "Total Assets"},
{"card": "New Assets (This Year)"},
{"card": "Asset Value"}
]
2020-05-08 11:09:17 +00:00
}]
2020-06-11 16:03:43 +00:00
def get_charts(fiscal_year, year_start_date, year_end_date):
company = get_company_for_dashboards()
2020-05-08 11:09:17 +00:00
return [
{
"name": "Asset Value Analytics",
"chart_name": _("Asset Value Analytics"),
"chart_type": "Report",
"report_name": "Fixed Asset Register",
"is_custom": 1,
"group_by_type": "Count",
"number_of_groups": 0,
"is_public": 0,
"timespan": "Last Year",
"time_interval": "Yearly",
"timeseries": 0,
"filters_json": json.dumps({
"company": company,
"status": "In Location",
"filter_based_on": "Fiscal Year",
2020-06-12 09:59:40 +00:00
"from_fiscal_year": fiscal_year.get('name'),
"to_fiscal_year": fiscal_year.get('name'),
"period_start_date": year_start_date,
"period_end_date": year_end_date,
"date_based_on": "Purchase Date",
"group_by": "--Select a group--"
}),
"type": "Bar",
"custom_options": json.dumps({
"type": "bar",
"barOptions": { "stacked": 1 },
"axisOptions": { "shortenYAxisNumbers": 1 },
"tooltipOptions": {}
}),
"doctype": "Dashboard Chart",
"y_axis": []
},
2020-05-11 09:42:11 +00:00
{
"name": "Category-wise Asset Value",
"chart_name": _("Category-wise Asset Value"),
2020-05-11 09:42:11 +00:00
"chart_type": "Report",
"report_name": "Fixed Asset Register",
2020-05-11 09:42:11 +00:00
"x_field": "asset_category",
"timeseries": 0,
"filters_json": json.dumps({
"company": company,
"status":"In Location",
"group_by":"Asset Category",
"is_existing_asset":0
}),
2020-05-11 09:42:11 +00:00
"type": "Donut",
"doctype": "Dashboard Chart",
"y_axis": [
{
"parent": "Category-wise Asset Value",
"parentfield": "y_axis",
"parenttype": "Dashboard Chart",
"y_field": "asset_value",
"doctype": "Dashboard Chart Field"
}
],
"custom_options": json.dumps({
"type": "donut",
"height": 300,
"axisOptions": {"shortenYAxisNumbers": 1}
})
},
{
"name": "Location-wise Asset Value",
"chart_name": "Location-wise Asset Value",
"chart_type": "Report",
"report_name": "Fixed Asset Register",
2020-05-11 09:42:11 +00:00
"x_field": "location",
"timeseries": 0,
"filters_json": json.dumps({
"company": company,
"status":"In Location",
"group_by":"Location",
"is_existing_asset":0
}),
2020-05-11 09:42:11 +00:00
"type": "Donut",
"doctype": "Dashboard Chart",
"y_axis": [
{
"parent": "Location-wise Asset Value",
"parentfield": "y_axis",
"parenttype": "Dashboard Chart",
"y_field": "asset_value",
"doctype": "Dashboard Chart Field"
}
],
"custom_options": json.dumps({
"type": "donut",
"height": 300,
"axisOptions": {"shortenYAxisNumbers": 1}
})
}
]
2020-06-11 16:03:43 +00:00
def get_number_cards(fiscal_year, year_start_date, year_end_date):
return [
{
"name": "Total Assets",
"label": _("Total Assets"),
"function": "Count",
"document_type": "Asset",
"is_public": 1,
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"filters_json": "[]",
"doctype": "Number Card",
},
{
"name": "New Assets (This Year)",
"label": _("New Assets (This Year)"),
"function": "Count",
"document_type": "Asset",
"is_public": 1,
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"filters_json": json.dumps([
['Asset', 'creation', 'between', [year_start_date, year_end_date]]
]),
"doctype": "Number Card",
},
{
"name": "Asset Value",
"label": _("Asset Value"),
"function": "Sum",
"aggregate_function_based_on": "value_after_depreciation",
"document_type": "Asset",
"is_public": 1,
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"filters_json": "[]",
"doctype": "Number Card"
}
2020-06-11 16:03:43 +00:00
]