blob: 9af45d16b629d8c8f7a9dae0d647887641e58cf2 [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
4import frappe
5import json
Nabin Hait054aafa2020-05-20 18:21:51 +05306from frappe.utils import nowdate, add_months, get_date_str
7from frappe import _
8from erpnext.accounts.utils import get_fiscal_year
9
Saqib Ansari22aec572020-05-08 16:39:17 +053010
11def get_data():
12 return frappe._dict({
13 "dashboards": get_dashboards(),
Saqib Ansari89906972020-05-12 17:38:34 +053014 "charts": get_charts(),
15 "number_cards": get_number_cards(),
Saqib Ansari22aec572020-05-08 16:39:17 +053016 })
17
18def get_dashboards():
19 return [{
20 "name": "Asset",
21 "dashboard_name": "Asset",
22 "charts": [
Saqib Ansari89906972020-05-12 17:38:34 +053023 { "chart": "Asset Value Analytics", "width": "Full" },
24 { "chart": "Category-wise Asset Value", "width": "Half" },
25 { "chart": "Location-wise Asset Value", "width": "Half" },
Nabin Hait054aafa2020-05-20 18:21:51 +053026 ],
27 "cards": [
28 {"card": "Total Assets"},
29 {"card": "New Assets (This Year)"},
30 {"card": "Asset Value"}
31 ]
Saqib Ansari22aec572020-05-08 16:39:17 +053032 }]
33
Nabin Hait054aafa2020-05-20 18:21:51 +053034fiscal_year = get_fiscal_year(date=nowdate())
35year_start_date = get_date_str(fiscal_year[1])
36year_end_date = get_date_str(fiscal_year[2])
37
38
Saqib Ansari22aec572020-05-08 16:39:17 +053039def get_charts():
Saqib Ansari89906972020-05-12 17:38:34 +053040 company = get_company_for_dashboards()
Saqib Ansari22aec572020-05-08 16:39:17 +053041 return [
Saqib Ansariecddf332020-05-11 15:12:11 +053042 {
Saqib Ansari89906972020-05-12 17:38:34 +053043 "name": "Asset Value Analytics",
Nabin Hait054aafa2020-05-20 18:21:51 +053044 "chart_name": _("Asset Value Analytics"),
Saqib Ansari89906972020-05-12 17:38:34 +053045 "chart_type": "Report",
46 "report_name": "Fixed Asset Register",
47 "is_custom": 1,
48 "group_by_type": "Count",
49 "number_of_groups": 0,
50 "is_public": 0,
51 "timespan": "Last Year",
52 "time_interval": "Yearly",
53 "timeseries": 0,
54 "filters_json": json.dumps({
55 "company": company,
56 "status": "In Location",
57 "filter_based_on": "Fiscal Year",
Nabin Hait054aafa2020-05-20 18:21:51 +053058 "from_fiscal_year": fiscal_year[0],
59 "to_fiscal_year": fiscal_year[0],
60 "period_start_date": year_start_date,
61 "period_end_date": year_end_date,
Saqib Ansari89906972020-05-12 17:38:34 +053062 "date_based_on": "Purchase Date",
63 "group_by": "--Select a group--"
64 }),
65 "type": "Bar",
66 "custom_options": json.dumps({
67 "type": "bar",
68 "barOptions": { "stacked": 1 },
69 "axisOptions": { "shortenYAxisNumbers": 1 },
70 "tooltipOptions": {}
71 }),
72 "doctype": "Dashboard Chart",
73 "y_axis": []
74 },
75 {
Saqib Ansariecddf332020-05-11 15:12:11 +053076 "name": "Category-wise Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +053077 "chart_name": _("Category-wise Asset Value"),
Saqib Ansariecddf332020-05-11 15:12:11 +053078 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +053079 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +053080 "x_field": "asset_category",
81 "timeseries": 0,
Saqib Ansari89906972020-05-12 17:38:34 +053082 "filters_json": json.dumps({
83 "company": company,
84 "status":"In Location",
85 "group_by":"Asset Category",
86 "is_existing_asset":0
87 }),
Saqib Ansariecddf332020-05-11 15:12:11 +053088 "type": "Donut",
89 "doctype": "Dashboard Chart",
90 "y_axis": [
91 {
92 "parent": "Category-wise Asset Value",
93 "parentfield": "y_axis",
94 "parenttype": "Dashboard Chart",
95 "y_field": "asset_value",
96 "doctype": "Dashboard Chart Field"
97 }
98 ],
99 "custom_options": json.dumps({
100 "type": "donut",
101 "height": 300,
102 "axisOptions": {"shortenYAxisNumbers": 1}
103 })
104 },
105 {
106 "name": "Location-wise Asset Value",
107 "chart_name": "Location-wise Asset Value",
108 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +0530109 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +0530110 "x_field": "location",
111 "timeseries": 0,
Saqib Ansari89906972020-05-12 17:38:34 +0530112 "filters_json": json.dumps({
113 "company": company,
114 "status":"In Location",
115 "group_by":"Location",
116 "is_existing_asset":0
117 }),
Saqib Ansariecddf332020-05-11 15:12:11 +0530118 "type": "Donut",
119 "doctype": "Dashboard Chart",
120 "y_axis": [
121 {
122 "parent": "Location-wise Asset Value",
123 "parentfield": "y_axis",
124 "parenttype": "Dashboard Chart",
125 "y_field": "asset_value",
126 "doctype": "Dashboard Chart Field"
127 }
128 ],
129 "custom_options": json.dumps({
130 "type": "donut",
131 "height": 300,
132 "axisOptions": {"shortenYAxisNumbers": 1}
133 })
Saqib Ansari89906972020-05-12 17:38:34 +0530134 }
135 ]
136
137def get_number_cards():
138 return [
139 {
Nabin Hait054aafa2020-05-20 18:21:51 +0530140 "name": "Total Assets",
141 "label": _("Total Assets"),
142 "function": "Count",
143 "document_type": "Asset",
144 "is_public": 1,
145 "show_percentage_stats": 1,
146 "stats_time_interval": "Monthly",
147 "filters_json": "[]",
148 "doctype": "Number Card",
149 },
150 {
151 "name": "New Assets (This Year)",
152 "label": _("New Assets (This Year)"),
153 "function": "Count",
154 "document_type": "Asset",
155 "is_public": 1,
156 "show_percentage_stats": 1,
157 "stats_time_interval": "Monthly",
158 "filters_json": json.dumps([
159 ['Asset', 'creation', 'between', [year_start_date, year_end_date]]
160 ]),
161 "doctype": "Number Card",
162 },
163 {
Saqib Ansari89906972020-05-12 17:38:34 +0530164 "name": "Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +0530165 "label": _("Asset Value"),
Saqib Ansari89906972020-05-12 17:38:34 +0530166 "function": "Sum",
167 "aggregate_function_based_on": "value_after_depreciation",
168 "document_type": "Asset",
169 "is_public": 1,
170 "show_percentage_stats": 1,
171 "stats_time_interval": "Monthly",
172 "filters_json": "[]",
Nabin Hait054aafa2020-05-20 18:21:51 +0530173 "doctype": "Number Card"
Saqib Ansari89906972020-05-12 17:38:34 +0530174 }
175 ]
176
177def get_company_for_dashboards():
178 company = frappe.defaults.get_defaults().company
179 if company:
180 return company
181 else:
182 company_list = frappe.get_list("Company")
183 if company_list:
184 return company_list[0].name
Saqib Ansari89906972020-05-12 17:38:34 +0530185 return None