blob: fc9ba386a382aa050ba0bd97531de627a66b174d [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
16 fiscal_year = _get_fiscal_year(nowdate())
17
18 if not fiscal_year:
19 return frappe._dict()
20
Ankush Menat494bd9e2022-03-28 18:52:46 +053021 year_start_date = get_date_str(fiscal_year.get("year_start_date"))
22 year_end_date = get_date_str(fiscal_year.get("year_end_date"))
Deepesh Garg9df45322020-06-11 21:33:43 +053023
Ankush Menat494bd9e2022-03-28 18:52:46 +053024 return frappe._dict(
25 {
26 "dashboards": get_dashboards(),
27 "charts": get_charts(fiscal_year, year_start_date, year_end_date),
28 "number_cards": get_number_cards(fiscal_year, year_start_date, year_end_date),
29 }
30 )
31
Saqib Ansari22aec572020-05-08 16:39:17 +053032
33def get_dashboards():
Ankush Menat494bd9e2022-03-28 18:52:46 +053034 return [
35 {
36 "name": "Asset",
37 "dashboard_name": "Asset",
38 "charts": [
39 {"chart": "Asset Value Analytics", "width": "Full"},
40 {"chart": "Category-wise Asset Value", "width": "Half"},
41 {"chart": "Location-wise Asset Value", "width": "Half"},
42 ],
43 "cards": [
44 {"card": "Total Assets"},
45 {"card": "New Assets (This Year)"},
46 {"card": "Asset Value"},
47 ],
48 }
49 ]
50
Saqib Ansari22aec572020-05-08 16:39:17 +053051
Deepesh Garg9df45322020-06-11 21:33:43 +053052def get_charts(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +053053 company = get_company_for_dashboards()
Saqib Ansari22aec572020-05-08 16:39:17 +053054 return [
Saqib Ansariecddf332020-05-11 15:12:11 +053055 {
Saqib Ansari89906972020-05-12 17:38:34 +053056 "name": "Asset Value Analytics",
Nabin Hait054aafa2020-05-20 18:21:51 +053057 "chart_name": _("Asset Value Analytics"),
Saqib Ansari89906972020-05-12 17:38:34 +053058 "chart_type": "Report",
59 "report_name": "Fixed Asset Register",
60 "is_custom": 1,
61 "group_by_type": "Count",
62 "number_of_groups": 0,
63 "is_public": 0,
64 "timespan": "Last Year",
65 "time_interval": "Yearly",
66 "timeseries": 0,
Ankush Menat494bd9e2022-03-28 18:52:46 +053067 "filters_json": json.dumps(
68 {
69 "company": company,
70 "status": "In Location",
71 "filter_based_on": "Fiscal Year",
72 "from_fiscal_year": fiscal_year.get("name"),
73 "to_fiscal_year": fiscal_year.get("name"),
74 "period_start_date": year_start_date,
75 "period_end_date": year_end_date,
76 "date_based_on": "Purchase Date",
77 "group_by": "--Select a group--",
78 }
79 ),
Saqib Ansari89906972020-05-12 17:38:34 +053080 "type": "Bar",
Ankush Menat494bd9e2022-03-28 18:52:46 +053081 "custom_options": json.dumps(
82 {
83 "type": "bar",
84 "barOptions": {"stacked": 1},
85 "axisOptions": {"shortenYAxisNumbers": 1},
86 "tooltipOptions": {},
87 }
88 ),
Saqib Ansari89906972020-05-12 17:38:34 +053089 "doctype": "Dashboard Chart",
Ankush Menat494bd9e2022-03-28 18:52:46 +053090 "y_axis": [],
Saqib Ansari89906972020-05-12 17:38:34 +053091 },
92 {
Saqib Ansariecddf332020-05-11 15:12:11 +053093 "name": "Category-wise Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +053094 "chart_name": _("Category-wise Asset Value"),
Saqib Ansariecddf332020-05-11 15:12:11 +053095 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +053096 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +053097 "x_field": "asset_category",
98 "timeseries": 0,
Ankush Menat494bd9e2022-03-28 18:52:46 +053099 "filters_json": json.dumps(
100 {
101 "company": company,
102 "status": "In Location",
103 "group_by": "Asset Category",
104 "is_existing_asset": 0,
105 }
106 ),
Saqib Ansariecddf332020-05-11 15:12:11 +0530107 "type": "Donut",
108 "doctype": "Dashboard Chart",
109 "y_axis": [
110 {
111 "parent": "Category-wise Asset Value",
112 "parentfield": "y_axis",
113 "parenttype": "Dashboard Chart",
114 "y_field": "asset_value",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530115 "doctype": "Dashboard Chart Field",
Saqib Ansariecddf332020-05-11 15:12:11 +0530116 }
117 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530118 "custom_options": json.dumps(
119 {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}}
120 ),
Saqib Ansariecddf332020-05-11 15:12:11 +0530121 },
122 {
123 "name": "Location-wise Asset Value",
124 "chart_name": "Location-wise Asset Value",
125 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +0530126 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +0530127 "x_field": "location",
128 "timeseries": 0,
Ankush Menat494bd9e2022-03-28 18:52:46 +0530129 "filters_json": json.dumps(
130 {"company": company, "status": "In Location", "group_by": "Location", "is_existing_asset": 0}
131 ),
Saqib Ansariecddf332020-05-11 15:12:11 +0530132 "type": "Donut",
133 "doctype": "Dashboard Chart",
134 "y_axis": [
135 {
136 "parent": "Location-wise Asset Value",
137 "parentfield": "y_axis",
138 "parenttype": "Dashboard Chart",
139 "y_field": "asset_value",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530140 "doctype": "Dashboard Chart Field",
Saqib Ansariecddf332020-05-11 15:12:11 +0530141 }
142 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530143 "custom_options": json.dumps(
144 {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}}
145 ),
146 },
Saqib Ansari89906972020-05-12 17:38:34 +0530147 ]
148
Ankush Menat494bd9e2022-03-28 18:52:46 +0530149
Deepesh Garg9df45322020-06-11 21:33:43 +0530150def get_number_cards(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +0530151 return [
152 {
Nabin Hait054aafa2020-05-20 18:21:51 +0530153 "name": "Total Assets",
154 "label": _("Total Assets"),
155 "function": "Count",
156 "document_type": "Asset",
157 "is_public": 1,
158 "show_percentage_stats": 1,
159 "stats_time_interval": "Monthly",
160 "filters_json": "[]",
161 "doctype": "Number Card",
162 },
163 {
164 "name": "New Assets (This Year)",
165 "label": _("New Assets (This Year)"),
166 "function": "Count",
167 "document_type": "Asset",
168 "is_public": 1,
169 "show_percentage_stats": 1,
170 "stats_time_interval": "Monthly",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530171 "filters_json": json.dumps(
172 [["Asset", "creation", "between", [year_start_date, year_end_date]]]
173 ),
Nabin Hait054aafa2020-05-20 18:21:51 +0530174 "doctype": "Number Card",
175 },
176 {
Saqib Ansari89906972020-05-12 17:38:34 +0530177 "name": "Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +0530178 "label": _("Asset Value"),
Saqib Ansari89906972020-05-12 17:38:34 +0530179 "function": "Sum",
180 "aggregate_function_based_on": "value_after_depreciation",
181 "document_type": "Asset",
182 "is_public": 1,
183 "show_percentage_stats": 1,
184 "stats_time_interval": "Monthly",
185 "filters_json": "[]",
Ankush Menat494bd9e2022-03-28 18:52:46 +0530186 "doctype": "Number Card",
187 },
Ankush Menat4551d7d2021-08-19 13:41:10 +0530188 ]