# 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 _ from erpnext.accounts.utils import get_fiscal_year def get_data(): return frappe._dict({ "dashboards": get_dashboards(), "charts": get_charts(), "number_cards": get_number_cards(), }) 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"} ] }] fiscal_year = get_fiscal_year(date=nowdate()) year_start_date = get_date_str(fiscal_year[1]) year_end_date = get_date_str(fiscal_year[2]) def get_charts(): company = get_company_for_dashboards() 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", "from_fiscal_year": fiscal_year[0], "to_fiscal_year": fiscal_year[0], "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": [] }, { "name": "Category-wise Asset Value", "chart_name": _("Category-wise Asset Value"), "chart_type": "Report", "report_name": "Fixed Asset Register", "x_field": "asset_category", "timeseries": 0, "filters_json": json.dumps({ "company": company, "status":"In Location", "group_by":"Asset Category", "is_existing_asset":0 }), "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", "x_field": "location", "timeseries": 0, "filters_json": json.dumps({ "company": company, "status":"In Location", "group_by":"Location", "is_existing_asset":0 }), "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} }) } ] def get_number_cards(): 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" } ] 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