blob: 39f0f1a88be4b37bc8088a433fe3b6c043dc5317 [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
Deepesh Garg7e974c92020-06-12 15:29:40 +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
Saqib Ansari22aec572020-05-08 16:39:17 +053024 return frappe._dict({
25 "dashboards": get_dashboards(),
Deepesh Garg9df45322020-06-11 21:33:43 +053026 "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),
Saqib Ansari22aec572020-05-08 16:39:17 +053028 })
29
30def get_dashboards():
31 return [{
32 "name": "Asset",
33 "dashboard_name": "Asset",
34 "charts": [
Saqib Ansari89906972020-05-12 17:38:34 +053035 { "chart": "Asset Value Analytics", "width": "Full" },
36 { "chart": "Category-wise Asset Value", "width": "Half" },
37 { "chart": "Location-wise Asset Value", "width": "Half" },
Nabin Hait054aafa2020-05-20 18:21:51 +053038 ],
39 "cards": [
40 {"card": "Total Assets"},
41 {"card": "New Assets (This Year)"},
42 {"card": "Asset Value"}
43 ]
Saqib Ansari22aec572020-05-08 16:39:17 +053044 }]
45
Deepesh Garg9df45322020-06-11 21:33:43 +053046def get_charts(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +053047 company = get_company_for_dashboards()
Saqib Ansari22aec572020-05-08 16:39:17 +053048 return [
Saqib Ansariecddf332020-05-11 15:12:11 +053049 {
Saqib Ansari89906972020-05-12 17:38:34 +053050 "name": "Asset Value Analytics",
Nabin Hait054aafa2020-05-20 18:21:51 +053051 "chart_name": _("Asset Value Analytics"),
Saqib Ansari89906972020-05-12 17:38:34 +053052 "chart_type": "Report",
53 "report_name": "Fixed Asset Register",
54 "is_custom": 1,
55 "group_by_type": "Count",
56 "number_of_groups": 0,
57 "is_public": 0,
58 "timespan": "Last Year",
59 "time_interval": "Yearly",
60 "timeseries": 0,
61 "filters_json": json.dumps({
62 "company": company,
63 "status": "In Location",
64 "filter_based_on": "Fiscal Year",
Deepesh Garg7e974c92020-06-12 15:29:40 +053065 "from_fiscal_year": fiscal_year.get('name'),
66 "to_fiscal_year": fiscal_year.get('name'),
Nabin Hait054aafa2020-05-20 18:21:51 +053067 "period_start_date": year_start_date,
68 "period_end_date": year_end_date,
Saqib Ansari89906972020-05-12 17:38:34 +053069 "date_based_on": "Purchase Date",
70 "group_by": "--Select a group--"
71 }),
72 "type": "Bar",
73 "custom_options": json.dumps({
74 "type": "bar",
75 "barOptions": { "stacked": 1 },
76 "axisOptions": { "shortenYAxisNumbers": 1 },
77 "tooltipOptions": {}
78 }),
79 "doctype": "Dashboard Chart",
80 "y_axis": []
81 },
82 {
Saqib Ansariecddf332020-05-11 15:12:11 +053083 "name": "Category-wise Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +053084 "chart_name": _("Category-wise Asset Value"),
Saqib Ansariecddf332020-05-11 15:12:11 +053085 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +053086 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +053087 "x_field": "asset_category",
88 "timeseries": 0,
Saqib Ansari89906972020-05-12 17:38:34 +053089 "filters_json": json.dumps({
90 "company": company,
91 "status":"In Location",
92 "group_by":"Asset Category",
93 "is_existing_asset":0
94 }),
Saqib Ansariecddf332020-05-11 15:12:11 +053095 "type": "Donut",
96 "doctype": "Dashboard Chart",
97 "y_axis": [
98 {
99 "parent": "Category-wise Asset Value",
100 "parentfield": "y_axis",
101 "parenttype": "Dashboard Chart",
102 "y_field": "asset_value",
103 "doctype": "Dashboard Chart Field"
104 }
105 ],
106 "custom_options": json.dumps({
107 "type": "donut",
108 "height": 300,
109 "axisOptions": {"shortenYAxisNumbers": 1}
110 })
111 },
112 {
113 "name": "Location-wise Asset Value",
114 "chart_name": "Location-wise Asset Value",
115 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +0530116 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +0530117 "x_field": "location",
118 "timeseries": 0,
Saqib Ansari89906972020-05-12 17:38:34 +0530119 "filters_json": json.dumps({
120 "company": company,
121 "status":"In Location",
122 "group_by":"Location",
123 "is_existing_asset":0
124 }),
Saqib Ansariecddf332020-05-11 15:12:11 +0530125 "type": "Donut",
126 "doctype": "Dashboard Chart",
127 "y_axis": [
128 {
129 "parent": "Location-wise Asset Value",
130 "parentfield": "y_axis",
131 "parenttype": "Dashboard Chart",
132 "y_field": "asset_value",
133 "doctype": "Dashboard Chart Field"
134 }
135 ],
136 "custom_options": json.dumps({
137 "type": "donut",
138 "height": 300,
139 "axisOptions": {"shortenYAxisNumbers": 1}
140 })
Saqib Ansari89906972020-05-12 17:38:34 +0530141 }
142 ]
143
Deepesh Garg9df45322020-06-11 21:33:43 +0530144def get_number_cards(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +0530145 return [
146 {
Nabin Hait054aafa2020-05-20 18:21:51 +0530147 "name": "Total Assets",
148 "label": _("Total Assets"),
149 "function": "Count",
150 "document_type": "Asset",
151 "is_public": 1,
152 "show_percentage_stats": 1,
153 "stats_time_interval": "Monthly",
154 "filters_json": "[]",
155 "doctype": "Number Card",
156 },
157 {
158 "name": "New Assets (This Year)",
159 "label": _("New Assets (This Year)"),
160 "function": "Count",
161 "document_type": "Asset",
162 "is_public": 1,
163 "show_percentage_stats": 1,
164 "stats_time_interval": "Monthly",
165 "filters_json": json.dumps([
166 ['Asset', 'creation', 'between', [year_start_date, year_end_date]]
167 ]),
168 "doctype": "Number Card",
169 },
170 {
Saqib Ansari89906972020-05-12 17:38:34 +0530171 "name": "Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +0530172 "label": _("Asset Value"),
Saqib Ansari89906972020-05-12 17:38:34 +0530173 "function": "Sum",
174 "aggregate_function_based_on": "value_after_depreciation",
175 "document_type": "Asset",
176 "is_public": 1,
177 "show_percentage_stats": 1,
178 "stats_time_interval": "Monthly",
179 "filters_json": "[]",
Nabin Hait054aafa2020-05-20 18:21:51 +0530180 "doctype": "Number Card"
Saqib Ansari89906972020-05-12 17:38:34 +0530181 }
Ankush Menat4551d7d2021-08-19 13:41:10 +0530182 ]