blob: 3b1d14440cfc9e582b39189c6fb81bf9eba3ae2d [file] [log] [blame]
Saqib Ansari22aec572020-05-08 16:39:17 +05301# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
Saqib Ansari22aec572020-05-08 16:39:17 +05304import json
Chillar Anand915b3432021-09-02 16:44:59 +05305
6import frappe
Nabin Hait054aafa2020-05-20 18:21:51 +05307from frappe import _
Chillar Anand915b3432021-09-02 16:44:59 +05308from frappe.utils import get_date_str, nowdate
9
Deepesh Garg9df45322020-06-11 21:33:43 +053010from erpnext.accounts.dashboard_fixtures import _get_fiscal_year
11from erpnext.buying.dashboard_fixtures import get_company_for_dashboards
Saqib Ansari22aec572020-05-08 16:39:17 +053012
Chillar Anand915b3432021-09-02 16:44:59 +053013
Saqib Ansari22aec572020-05-08 16:39:17 +053014def get_data():
Deepesh Garg9df45322020-06-11 21:33:43 +053015 fiscal_year = _get_fiscal_year(nowdate())
16
17 if not fiscal_year:
18 return frappe._dict()
19
Ankush Menat494bd9e2022-03-28 18:52:46 +053020 year_start_date = get_date_str(fiscal_year.get("year_start_date"))
21 year_end_date = get_date_str(fiscal_year.get("year_end_date"))
Deepesh Garg9df45322020-06-11 21:33:43 +053022
Ankush Menat494bd9e2022-03-28 18:52:46 +053023 return frappe._dict(
24 {
25 "dashboards": get_dashboards(),
26 "charts": get_charts(fiscal_year, year_start_date, year_end_date),
27 "number_cards": get_number_cards(fiscal_year, year_start_date, year_end_date),
28 }
29 )
30
Saqib Ansari22aec572020-05-08 16:39:17 +053031
32def get_dashboards():
Ankush Menat494bd9e2022-03-28 18:52:46 +053033 return [
34 {
35 "name": "Asset",
36 "dashboard_name": "Asset",
37 "charts": [
38 {"chart": "Asset Value Analytics", "width": "Full"},
39 {"chart": "Category-wise Asset Value", "width": "Half"},
40 {"chart": "Location-wise Asset Value", "width": "Half"},
41 ],
42 "cards": [
43 {"card": "Total Assets"},
44 {"card": "New Assets (This Year)"},
45 {"card": "Asset Value"},
46 ],
47 }
48 ]
49
Saqib Ansari22aec572020-05-08 16:39:17 +053050
Deepesh Garg9df45322020-06-11 21:33:43 +053051def get_charts(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +053052 company = get_company_for_dashboards()
Saqib Ansari22aec572020-05-08 16:39:17 +053053 return [
Saqib Ansariecddf332020-05-11 15:12:11 +053054 {
Saqib Ansari89906972020-05-12 17:38:34 +053055 "name": "Asset Value Analytics",
Nabin Hait054aafa2020-05-20 18:21:51 +053056 "chart_name": _("Asset Value Analytics"),
Saqib Ansari89906972020-05-12 17:38:34 +053057 "chart_type": "Report",
58 "report_name": "Fixed Asset Register",
59 "is_custom": 1,
60 "group_by_type": "Count",
61 "number_of_groups": 0,
62 "is_public": 0,
63 "timespan": "Last Year",
64 "time_interval": "Yearly",
65 "timeseries": 0,
Ankush Menat494bd9e2022-03-28 18:52:46 +053066 "filters_json": json.dumps(
67 {
68 "company": company,
69 "status": "In Location",
70 "filter_based_on": "Fiscal Year",
71 "from_fiscal_year": fiscal_year.get("name"),
72 "to_fiscal_year": fiscal_year.get("name"),
73 "period_start_date": year_start_date,
74 "period_end_date": year_end_date,
75 "date_based_on": "Purchase Date",
76 "group_by": "--Select a group--",
77 }
78 ),
Saqib Ansari89906972020-05-12 17:38:34 +053079 "type": "Bar",
Ankush Menat494bd9e2022-03-28 18:52:46 +053080 "custom_options": json.dumps(
81 {
82 "type": "bar",
83 "barOptions": {"stacked": 1},
84 "axisOptions": {"shortenYAxisNumbers": 1},
85 "tooltipOptions": {},
86 }
87 ),
Saqib Ansari89906972020-05-12 17:38:34 +053088 "doctype": "Dashboard Chart",
Ankush Menat494bd9e2022-03-28 18:52:46 +053089 "y_axis": [],
Saqib Ansari89906972020-05-12 17:38:34 +053090 },
91 {
Saqib Ansariecddf332020-05-11 15:12:11 +053092 "name": "Category-wise Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +053093 "chart_name": _("Category-wise Asset Value"),
Saqib Ansariecddf332020-05-11 15:12:11 +053094 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +053095 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +053096 "x_field": "asset_category",
97 "timeseries": 0,
Ankush Menat494bd9e2022-03-28 18:52:46 +053098 "filters_json": json.dumps(
99 {
100 "company": company,
101 "status": "In Location",
102 "group_by": "Asset Category",
103 "is_existing_asset": 0,
104 }
105 ),
Saqib Ansariecddf332020-05-11 15:12:11 +0530106 "type": "Donut",
107 "doctype": "Dashboard Chart",
108 "y_axis": [
109 {
110 "parent": "Category-wise Asset Value",
111 "parentfield": "y_axis",
112 "parenttype": "Dashboard Chart",
113 "y_field": "asset_value",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530114 "doctype": "Dashboard Chart Field",
Saqib Ansariecddf332020-05-11 15:12:11 +0530115 }
116 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530117 "custom_options": json.dumps(
118 {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}}
119 ),
Saqib Ansariecddf332020-05-11 15:12:11 +0530120 },
121 {
122 "name": "Location-wise Asset Value",
123 "chart_name": "Location-wise Asset Value",
124 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +0530125 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +0530126 "x_field": "location",
127 "timeseries": 0,
Ankush Menat494bd9e2022-03-28 18:52:46 +0530128 "filters_json": json.dumps(
129 {"company": company, "status": "In Location", "group_by": "Location", "is_existing_asset": 0}
130 ),
Saqib Ansariecddf332020-05-11 15:12:11 +0530131 "type": "Donut",
132 "doctype": "Dashboard Chart",
133 "y_axis": [
134 {
135 "parent": "Location-wise Asset Value",
136 "parentfield": "y_axis",
137 "parenttype": "Dashboard Chart",
138 "y_field": "asset_value",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530139 "doctype": "Dashboard Chart Field",
Saqib Ansariecddf332020-05-11 15:12:11 +0530140 }
141 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530142 "custom_options": json.dumps(
143 {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}}
144 ),
145 },
Saqib Ansari89906972020-05-12 17:38:34 +0530146 ]
147
Ankush Menat494bd9e2022-03-28 18:52:46 +0530148
Deepesh Garg9df45322020-06-11 21:33:43 +0530149def get_number_cards(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +0530150 return [
151 {
Nabin Hait054aafa2020-05-20 18:21:51 +0530152 "name": "Total Assets",
153 "label": _("Total Assets"),
154 "function": "Count",
155 "document_type": "Asset",
156 "is_public": 1,
157 "show_percentage_stats": 1,
158 "stats_time_interval": "Monthly",
159 "filters_json": "[]",
160 "doctype": "Number Card",
161 },
162 {
163 "name": "New Assets (This Year)",
164 "label": _("New Assets (This Year)"),
165 "function": "Count",
166 "document_type": "Asset",
167 "is_public": 1,
168 "show_percentage_stats": 1,
169 "stats_time_interval": "Monthly",
Akhil Narang3effaf22024-03-27 11:37:26 +0530170 "filters_json": json.dumps([["Asset", "creation", "between", [year_start_date, year_end_date]]]),
Nabin Hait054aafa2020-05-20 18:21:51 +0530171 "doctype": "Number Card",
172 },
173 {
Saqib Ansari89906972020-05-12 17:38:34 +0530174 "name": "Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +0530175 "label": _("Asset Value"),
Saqib Ansari89906972020-05-12 17:38:34 +0530176 "function": "Sum",
177 "aggregate_function_based_on": "value_after_depreciation",
178 "document_type": "Asset",
179 "is_public": 1,
180 "show_percentage_stats": 1,
181 "stats_time_interval": "Monthly",
182 "filters_json": "[]",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530183 "doctype": "Number Card",
184 },
Ankush Menat4551d7d2021-08-19 13:41:10 +0530185 ]