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 | fiscal_year = _get_fiscal_year(nowdate()) |
| 16 | |
| 17 | if not fiscal_year: |
| 18 | return frappe._dict() |
| 19 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 20 | year_start_date = get_date_str(fiscal_year.get("year_start_date")) |
| 21 | year_end_date = get_date_str(fiscal_year.get("year_end_date")) |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 22 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 23 | return frappe._dict( |
| 24 | { |
| 25 | "dashboards": get_dashboards(), |
| 26 | "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), |
| 28 | } |
| 29 | ) |
| 30 | |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 31 | |
| 32 | def get_dashboards(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 33 | return [ |
| 34 | { |
| 35 | "name": "Asset", |
| 36 | "dashboard_name": "Asset", |
| 37 | "charts": [ |
| 38 | {"chart": "Asset Value Analytics", "width": "Full"}, |
| 39 | {"chart": "Category-wise Asset Value", "width": "Half"}, |
| 40 | {"chart": "Location-wise Asset Value", "width": "Half"}, |
| 41 | ], |
| 42 | "cards": [ |
| 43 | {"card": "Total Assets"}, |
| 44 | {"card": "New Assets (This Year)"}, |
| 45 | {"card": "Asset Value"}, |
| 46 | ], |
| 47 | } |
| 48 | ] |
| 49 | |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 50 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 51 | def get_charts(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 52 | company = get_company_for_dashboards() |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 53 | return [ |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 54 | { |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 55 | "name": "Asset Value Analytics", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 56 | "chart_name": _("Asset Value Analytics"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 57 | "chart_type": "Report", |
| 58 | "report_name": "Fixed Asset Register", |
| 59 | "is_custom": 1, |
| 60 | "group_by_type": "Count", |
| 61 | "number_of_groups": 0, |
| 62 | "is_public": 0, |
| 63 | "timespan": "Last Year", |
| 64 | "time_interval": "Yearly", |
| 65 | "timeseries": 0, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 66 | "filters_json": json.dumps( |
| 67 | { |
| 68 | "company": company, |
| 69 | "status": "In Location", |
| 70 | "filter_based_on": "Fiscal Year", |
| 71 | "from_fiscal_year": fiscal_year.get("name"), |
| 72 | "to_fiscal_year": fiscal_year.get("name"), |
| 73 | "period_start_date": year_start_date, |
| 74 | "period_end_date": year_end_date, |
| 75 | "date_based_on": "Purchase Date", |
| 76 | "group_by": "--Select a group--", |
| 77 | } |
| 78 | ), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 79 | "type": "Bar", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 80 | "custom_options": json.dumps( |
| 81 | { |
| 82 | "type": "bar", |
| 83 | "barOptions": {"stacked": 1}, |
| 84 | "axisOptions": {"shortenYAxisNumbers": 1}, |
| 85 | "tooltipOptions": {}, |
| 86 | } |
| 87 | ), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 88 | "doctype": "Dashboard Chart", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 89 | "y_axis": [], |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 90 | }, |
| 91 | { |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 92 | "name": "Category-wise Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 93 | "chart_name": _("Category-wise Asset Value"), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 94 | "chart_type": "Report", |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 95 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 96 | "x_field": "asset_category", |
| 97 | "timeseries": 0, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 98 | "filters_json": json.dumps( |
| 99 | { |
| 100 | "company": company, |
| 101 | "status": "In Location", |
| 102 | "group_by": "Asset Category", |
| 103 | "is_existing_asset": 0, |
| 104 | } |
| 105 | ), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 106 | "type": "Donut", |
| 107 | "doctype": "Dashboard Chart", |
| 108 | "y_axis": [ |
| 109 | { |
| 110 | "parent": "Category-wise Asset Value", |
| 111 | "parentfield": "y_axis", |
| 112 | "parenttype": "Dashboard Chart", |
| 113 | "y_field": "asset_value", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 114 | "doctype": "Dashboard Chart Field", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 115 | } |
| 116 | ], |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 117 | "custom_options": json.dumps( |
| 118 | {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}} |
| 119 | ), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 120 | }, |
| 121 | { |
| 122 | "name": "Location-wise Asset Value", |
| 123 | "chart_name": "Location-wise Asset Value", |
| 124 | "chart_type": "Report", |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 125 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 126 | "x_field": "location", |
| 127 | "timeseries": 0, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 128 | "filters_json": json.dumps( |
| 129 | {"company": company, "status": "In Location", "group_by": "Location", "is_existing_asset": 0} |
| 130 | ), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 131 | "type": "Donut", |
| 132 | "doctype": "Dashboard Chart", |
| 133 | "y_axis": [ |
| 134 | { |
| 135 | "parent": "Location-wise Asset Value", |
| 136 | "parentfield": "y_axis", |
| 137 | "parenttype": "Dashboard Chart", |
| 138 | "y_field": "asset_value", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 139 | "doctype": "Dashboard Chart Field", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 140 | } |
| 141 | ], |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 142 | "custom_options": json.dumps( |
| 143 | {"type": "donut", "height": 300, "axisOptions": {"shortenYAxisNumbers": 1}} |
| 144 | ), |
| 145 | }, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 146 | ] |
| 147 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 148 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 149 | def get_number_cards(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 150 | return [ |
| 151 | { |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 152 | "name": "Total Assets", |
| 153 | "label": _("Total Assets"), |
| 154 | "function": "Count", |
| 155 | "document_type": "Asset", |
| 156 | "is_public": 1, |
| 157 | "show_percentage_stats": 1, |
| 158 | "stats_time_interval": "Monthly", |
| 159 | "filters_json": "[]", |
| 160 | "doctype": "Number Card", |
| 161 | }, |
| 162 | { |
| 163 | "name": "New Assets (This Year)", |
| 164 | "label": _("New Assets (This Year)"), |
| 165 | "function": "Count", |
| 166 | "document_type": "Asset", |
| 167 | "is_public": 1, |
| 168 | "show_percentage_stats": 1, |
| 169 | "stats_time_interval": "Monthly", |
Akhil Narang | 3effaf2 | 2024-03-27 11:37:26 +0530 | [diff] [blame] | 170 | "filters_json": json.dumps([["Asset", "creation", "between", [year_start_date, year_end_date]]]), |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 171 | "doctype": "Number Card", |
| 172 | }, |
| 173 | { |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 174 | "name": "Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 175 | "label": _("Asset Value"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 176 | "function": "Sum", |
| 177 | "aggregate_function_based_on": "value_after_depreciation", |
| 178 | "document_type": "Asset", |
| 179 | "is_public": 1, |
| 180 | "show_percentage_stats": 1, |
| 181 | "stats_time_interval": "Monthly", |
| 182 | "filters_json": "[]", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 183 | "doctype": "Number Card", |
| 184 | }, |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 185 | ] |