Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 1 | # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 4 | import json |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 5 | |
| 6 | import frappe |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 7 | from frappe import _ |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 8 | from frappe.utils import get_date_str, nowdate |
| 9 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 10 | from erpnext.accounts.dashboard_fixtures import _get_fiscal_year |
| 11 | from erpnext.buying.dashboard_fixtures import get_company_for_dashboards |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 12 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 13 | |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 14 | def get_data(): |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 15 | |
| 16 | fiscal_year = _get_fiscal_year(nowdate()) |
| 17 | |
| 18 | if not fiscal_year: |
| 19 | return frappe._dict() |
| 20 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 21 | 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 Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 23 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 24 | 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 Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 32 | |
| 33 | def get_dashboards(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 34 | 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 Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 51 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 52 | def get_charts(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 53 | company = get_company_for_dashboards() |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 54 | return [ |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 55 | { |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 56 | "name": "Asset Value Analytics", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 57 | "chart_name": _("Asset Value Analytics"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 58 | "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 Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 67 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 80 | "type": "Bar", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 81 | "custom_options": json.dumps( |
| 82 | { |
| 83 | "type": "bar", |
| 84 | "barOptions": {"stacked": 1}, |
| 85 | "axisOptions": {"shortenYAxisNumbers": 1}, |
| 86 | "tooltipOptions": {}, |
| 87 | } |
| 88 | ), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 89 | "doctype": "Dashboard Chart", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 90 | "y_axis": [], |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 91 | }, |
| 92 | { |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 93 | "name": "Category-wise Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 94 | "chart_name": _("Category-wise Asset Value"), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 95 | "chart_type": "Report", |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 96 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 97 | "x_field": "asset_category", |
| 98 | "timeseries": 0, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 99 | "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 Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 107 | "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 Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 115 | "doctype": "Dashboard Chart Field", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 116 | } |
| 117 | ], |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 118 | "custom_options": json.dumps( |
| 119 | {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}} |
| 120 | ), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 121 | }, |
| 122 | { |
| 123 | "name": "Location-wise Asset Value", |
| 124 | "chart_name": "Location-wise Asset Value", |
| 125 | "chart_type": "Report", |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 126 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 127 | "x_field": "location", |
| 128 | "timeseries": 0, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 129 | "filters_json": json.dumps( |
| 130 | {"company": company, "status": "In Location", "group_by": "Location", "is_existing_asset": 0} |
| 131 | ), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 132 | "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 Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 140 | "doctype": "Dashboard Chart Field", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 141 | } |
| 142 | ], |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 143 | "custom_options": json.dumps( |
| 144 | {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}} |
| 145 | ), |
| 146 | }, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 147 | ] |
| 148 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 149 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 150 | def get_number_cards(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 151 | return [ |
| 152 | { |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 153 | "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 Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 171 | "filters_json": json.dumps( |
| 172 | [["Asset", "creation", "between", [year_start_date, year_end_date]]] |
| 173 | ), |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 174 | "doctype": "Number Card", |
| 175 | }, |
| 176 | { |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 177 | "name": "Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 178 | "label": _("Asset Value"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 179 | "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 Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 186 | "doctype": "Number Card", |
| 187 | }, |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 188 | ] |