blob: 7f3c1de406a60cade4d4a67b0c60d98071e40317 [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 _
Deepesh Garg9df45322020-06-11 21:33:43 +05308from erpnext.accounts.dashboard_fixtures import _get_fiscal_year
9from erpnext.buying.dashboard_fixtures import get_company_for_dashboards
Saqib Ansari22aec572020-05-08 16:39:17 +053010
11def get_data():
Deepesh Garg9df45322020-06-11 21:33:43 +053012
13 fiscal_year = _get_fiscal_year(nowdate())
14
15 if not fiscal_year:
16 return frappe._dict()
17
Deepesh Garg7e974c92020-06-12 15:29:40 +053018 year_start_date = get_date_str(fiscal_year.get('year_start_date'))
19 year_end_date = get_date_str(fiscal_year.get('year_end_date'))
Deepesh Garg9df45322020-06-11 21:33:43 +053020
Saqib Ansari22aec572020-05-08 16:39:17 +053021 return frappe._dict({
22 "dashboards": get_dashboards(),
Deepesh Garg9df45322020-06-11 21:33:43 +053023 "charts": get_charts(fiscal_year, year_start_date, year_end_date),
24 "number_cards": get_number_cards(fiscal_year, year_start_date, year_end_date),
Saqib Ansari22aec572020-05-08 16:39:17 +053025 })
26
27def get_dashboards():
28 return [{
29 "name": "Asset",
30 "dashboard_name": "Asset",
31 "charts": [
Saqib Ansari89906972020-05-12 17:38:34 +053032 { "chart": "Asset Value Analytics", "width": "Full" },
33 { "chart": "Category-wise Asset Value", "width": "Half" },
34 { "chart": "Location-wise Asset Value", "width": "Half" },
Nabin Hait054aafa2020-05-20 18:21:51 +053035 ],
36 "cards": [
37 {"card": "Total Assets"},
38 {"card": "New Assets (This Year)"},
39 {"card": "Asset Value"}
40 ]
Saqib Ansari22aec572020-05-08 16:39:17 +053041 }]
42
Deepesh Garg9df45322020-06-11 21:33:43 +053043def get_charts(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +053044 company = get_company_for_dashboards()
Saqib Ansari22aec572020-05-08 16:39:17 +053045 return [
Saqib Ansariecddf332020-05-11 15:12:11 +053046 {
Saqib Ansari89906972020-05-12 17:38:34 +053047 "name": "Asset Value Analytics",
Nabin Hait054aafa2020-05-20 18:21:51 +053048 "chart_name": _("Asset Value Analytics"),
Saqib Ansari89906972020-05-12 17:38:34 +053049 "chart_type": "Report",
50 "report_name": "Fixed Asset Register",
51 "is_custom": 1,
52 "group_by_type": "Count",
53 "number_of_groups": 0,
54 "is_public": 0,
55 "timespan": "Last Year",
56 "time_interval": "Yearly",
57 "timeseries": 0,
58 "filters_json": json.dumps({
59 "company": company,
60 "status": "In Location",
61 "filter_based_on": "Fiscal Year",
Deepesh Garg7e974c92020-06-12 15:29:40 +053062 "from_fiscal_year": fiscal_year.get('name'),
63 "to_fiscal_year": fiscal_year.get('name'),
Nabin Hait054aafa2020-05-20 18:21:51 +053064 "period_start_date": year_start_date,
65 "period_end_date": year_end_date,
Saqib Ansari89906972020-05-12 17:38:34 +053066 "date_based_on": "Purchase Date",
67 "group_by": "--Select a group--"
68 }),
69 "type": "Bar",
70 "custom_options": json.dumps({
71 "type": "bar",
72 "barOptions": { "stacked": 1 },
73 "axisOptions": { "shortenYAxisNumbers": 1 },
74 "tooltipOptions": {}
75 }),
76 "doctype": "Dashboard Chart",
77 "y_axis": []
78 },
79 {
Saqib Ansariecddf332020-05-11 15:12:11 +053080 "name": "Category-wise Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +053081 "chart_name": _("Category-wise Asset Value"),
Saqib Ansariecddf332020-05-11 15:12:11 +053082 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +053083 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +053084 "x_field": "asset_category",
85 "timeseries": 0,
Saqib Ansari89906972020-05-12 17:38:34 +053086 "filters_json": json.dumps({
87 "company": company,
88 "status":"In Location",
89 "group_by":"Asset Category",
90 "is_existing_asset":0
91 }),
Saqib Ansariecddf332020-05-11 15:12:11 +053092 "type": "Donut",
93 "doctype": "Dashboard Chart",
94 "y_axis": [
95 {
96 "parent": "Category-wise Asset Value",
97 "parentfield": "y_axis",
98 "parenttype": "Dashboard Chart",
99 "y_field": "asset_value",
100 "doctype": "Dashboard Chart Field"
101 }
102 ],
103 "custom_options": json.dumps({
104 "type": "donut",
105 "height": 300,
106 "axisOptions": {"shortenYAxisNumbers": 1}
107 })
108 },
109 {
110 "name": "Location-wise Asset Value",
111 "chart_name": "Location-wise Asset Value",
112 "chart_type": "Report",
Saqib Ansari89906972020-05-12 17:38:34 +0530113 "report_name": "Fixed Asset Register",
Saqib Ansariecddf332020-05-11 15:12:11 +0530114 "x_field": "location",
115 "timeseries": 0,
Saqib Ansari89906972020-05-12 17:38:34 +0530116 "filters_json": json.dumps({
117 "company": company,
118 "status":"In Location",
119 "group_by":"Location",
120 "is_existing_asset":0
121 }),
Saqib Ansariecddf332020-05-11 15:12:11 +0530122 "type": "Donut",
123 "doctype": "Dashboard Chart",
124 "y_axis": [
125 {
126 "parent": "Location-wise Asset Value",
127 "parentfield": "y_axis",
128 "parenttype": "Dashboard Chart",
129 "y_field": "asset_value",
130 "doctype": "Dashboard Chart Field"
131 }
132 ],
133 "custom_options": json.dumps({
134 "type": "donut",
135 "height": 300,
136 "axisOptions": {"shortenYAxisNumbers": 1}
137 })
Saqib Ansari89906972020-05-12 17:38:34 +0530138 }
139 ]
140
Deepesh Garg9df45322020-06-11 21:33:43 +0530141def get_number_cards(fiscal_year, year_start_date, year_end_date):
Saqib Ansari89906972020-05-12 17:38:34 +0530142 return [
143 {
Nabin Hait054aafa2020-05-20 18:21:51 +0530144 "name": "Total Assets",
145 "label": _("Total Assets"),
146 "function": "Count",
147 "document_type": "Asset",
148 "is_public": 1,
149 "show_percentage_stats": 1,
150 "stats_time_interval": "Monthly",
151 "filters_json": "[]",
152 "doctype": "Number Card",
153 },
154 {
155 "name": "New Assets (This Year)",
156 "label": _("New Assets (This Year)"),
157 "function": "Count",
158 "document_type": "Asset",
159 "is_public": 1,
160 "show_percentage_stats": 1,
161 "stats_time_interval": "Monthly",
162 "filters_json": json.dumps([
163 ['Asset', 'creation', 'between', [year_start_date, year_end_date]]
164 ]),
165 "doctype": "Number Card",
166 },
167 {
Saqib Ansari89906972020-05-12 17:38:34 +0530168 "name": "Asset Value",
Nabin Hait054aafa2020-05-20 18:21:51 +0530169 "label": _("Asset Value"),
Saqib Ansari89906972020-05-12 17:38:34 +0530170 "function": "Sum",
171 "aggregate_function_based_on": "value_after_depreciation",
172 "document_type": "Asset",
173 "is_public": 1,
174 "show_percentage_stats": 1,
175 "stats_time_interval": "Monthly",
176 "filters_json": "[]",
Nabin Hait054aafa2020-05-20 18:21:51 +0530177 "doctype": "Number Card"
Saqib Ansari89906972020-05-12 17:38:34 +0530178 }
Deepesh Garg9df45322020-06-11 21:33:43 +0530179 ]