fix: dashboard fixtures
This commit is contained in:
parent
1dcf103398
commit
ecddf3358d
@ -8,8 +8,7 @@ import json
|
|||||||
def get_data():
|
def get_data():
|
||||||
return frappe._dict({
|
return frappe._dict({
|
||||||
"dashboards": get_dashboards(),
|
"dashboards": get_dashboards(),
|
||||||
"charts": get_charts(),
|
"charts": get_charts()
|
||||||
"number_cards": get_number_cards(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_dashboards():
|
def get_dashboards():
|
||||||
@ -24,73 +23,55 @@ def get_dashboards():
|
|||||||
|
|
||||||
def get_charts():
|
def get_charts():
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"name": "Category-wise Asset Value",
|
"name": "Category-wise Asset Value",
|
||||||
"chart_name": "Category-wise Asset Value",
|
"chart_name": "Category-wise Asset Value",
|
||||||
"chart_type": "Report",
|
"chart_type": "Report",
|
||||||
"report_name": "Category-wise Asset Value",
|
"report_name": "Fixed Asset Report",
|
||||||
"is_custom": 1,
|
"is_custom": 1,
|
||||||
"x_field": "asset_category",
|
"x_field": "asset_category",
|
||||||
"timeseries": 0,
|
"timeseries": 0,
|
||||||
"filters_json": "{}",
|
"filters_json": json.dumps("""{"status":"In Location","group_by":"Asset Category","is_existing_asset":0}"""),
|
||||||
"type": "Donut",
|
"type": "Donut",
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"y_axis": [
|
"y_axis": [
|
||||||
{
|
{
|
||||||
"parent": "Category-wise Asset Value",
|
"parent": "Category-wise Asset Value",
|
||||||
"parentfield": "y_axis",
|
"parentfield": "y_axis",
|
||||||
"parenttype": "Dashboard Chart",
|
"parenttype": "Dashboard Chart",
|
||||||
"y_field": "asset_value",
|
"y_field": "asset_value",
|
||||||
"doctype": "Dashboard Chart Field"
|
"doctype": "Dashboard Chart Field"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"custom_options": json.dumps({
|
"custom_options": json.dumps({
|
||||||
"type": "donut",
|
"type": "donut",
|
||||||
"height": 300,
|
"height": 300,
|
||||||
"axisOptions": {"shortenYAxisNumbers": 1}
|
"axisOptions": {"shortenYAxisNumbers": 1}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Location-wise Asset Value",
|
"name": "Location-wise Asset Value",
|
||||||
"chart_name": "Location-wise Asset Value",
|
"chart_name": "Location-wise Asset Value",
|
||||||
"chart_type": "Report",
|
"chart_type": "Report",
|
||||||
"report_name": "Location-wise Asset Value",
|
"report_name": "Location-wise Asset Value",
|
||||||
"is_custom": 1,
|
"is_custom": 1,
|
||||||
"x_field": "location",
|
"x_field": "location",
|
||||||
"timeseries": 0,
|
"timeseries": 0,
|
||||||
"filters_json": "{}",
|
"filters_json": json.dumps("""{"status":"In Location","group_by":"Location","is_existing_asset":0}"""),
|
||||||
"type": "Donut",
|
"type": "Donut",
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"y_axis": [
|
"y_axis": [
|
||||||
{
|
{
|
||||||
"parent": "Location-wise Asset Value",
|
"parent": "Location-wise Asset Value",
|
||||||
"parentfield": "y_axis",
|
"parentfield": "y_axis",
|
||||||
"parenttype": "Dashboard Chart",
|
"parenttype": "Dashboard Chart",
|
||||||
"y_field": "asset_value",
|
"y_field": "asset_value",
|
||||||
"doctype": "Dashboard Chart Field"
|
"doctype": "Dashboard Chart Field"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"custom_options": json.dumps({
|
"custom_options": json.dumps({
|
||||||
"type": "donut",
|
"type": "donut",
|
||||||
"height": 300,
|
"height": 300,
|
||||||
"axisOptions": {"shortenYAxisNumbers": 1}
|
"axisOptions": {"shortenYAxisNumbers": 1}
|
||||||
})
|
})
|
||||||
}
|
}]
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def get_number_cards():
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"name": "Asset Value",
|
|
||||||
"label": "Asset Value ",
|
|
||||||
"function": "Sum",
|
|
||||||
"aggregate_function_based_on": "gross_purchase_amount",
|
|
||||||
"document_type": "Asset",
|
|
||||||
"is_public": 0,
|
|
||||||
"show_percentage_stats": 1,
|
|
||||||
"stats_time_interval": "Monthly",
|
|
||||||
"filters_json": "[]",
|
|
||||||
"doctype": "Number Card"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
@ -10,7 +10,7 @@ def execute(filters=None):
|
|||||||
filters = frappe._dict(filters or {})
|
filters = frappe._dict(filters or {})
|
||||||
columns = get_columns(filters)
|
columns = get_columns(filters)
|
||||||
data = get_data(filters)
|
data = get_data(filters)
|
||||||
chart = prepare_chart_data(data, columns)
|
chart = prepare_chart_data(data) if not filters.get("group_by") else {}
|
||||||
|
|
||||||
return columns, data, None, chart
|
return columns, data, None, chart
|
||||||
|
|
||||||
@ -89,20 +89,25 @@ def get_data(filters):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def prepare_chart_data(data, columns):
|
def prepare_chart_data(data):
|
||||||
label_values_map = {}
|
labels, asset_values, depreciated_amounts = [], [], []
|
||||||
for d in data:
|
for d in data:
|
||||||
if not label_values_map.get(d.get('asset_category')):
|
labels.append(d.asset_id)
|
||||||
label_values_map[d.get('asset_category')] = 0
|
asset_values.append(d.asset_value)
|
||||||
label_values_map[d.get('asset_category')] += d.get('asset_value')
|
depreciated_amounts.append(d.depreciated_amount)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"data" : {
|
"data" : {
|
||||||
"labels": label_values_map.keys(),
|
"labels": labels,
|
||||||
"datasets": [{ "values": label_values_map.values() }]
|
"datasets": [
|
||||||
|
{ 'name': _('Asset Value'), 'values': asset_values },
|
||||||
|
{ 'name': _('Depreciatied Amount'), 'values': depreciated_amounts}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"type": "bar",
|
||||||
|
"barOptions": {
|
||||||
|
"stacked": 1
|
||||||
},
|
},
|
||||||
"type": 'donut',
|
|
||||||
"height": 250
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_finance_book_value_map(filters):
|
def get_finance_book_value_map(filters):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user