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 | |
Deepesh Garg | 7e974c9 | 2020-06-12 15:29:40 +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 | |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 24 | return frappe._dict({ |
| 25 | "dashboards": get_dashboards(), |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 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), |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 28 | }) |
| 29 | |
| 30 | def get_dashboards(): |
| 31 | return [{ |
| 32 | "name": "Asset", |
| 33 | "dashboard_name": "Asset", |
| 34 | "charts": [ |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 35 | { "chart": "Asset Value Analytics", "width": "Full" }, |
| 36 | { "chart": "Category-wise Asset Value", "width": "Half" }, |
| 37 | { "chart": "Location-wise Asset Value", "width": "Half" }, |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 38 | ], |
| 39 | "cards": [ |
| 40 | {"card": "Total Assets"}, |
| 41 | {"card": "New Assets (This Year)"}, |
| 42 | {"card": "Asset Value"} |
| 43 | ] |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 44 | }] |
| 45 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 46 | def get_charts(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 47 | company = get_company_for_dashboards() |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 48 | return [ |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 49 | { |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 50 | "name": "Asset Value Analytics", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 51 | "chart_name": _("Asset Value Analytics"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 52 | "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 Garg | 7e974c9 | 2020-06-12 15:29:40 +0530 | [diff] [blame] | 65 | "from_fiscal_year": fiscal_year.get('name'), |
| 66 | "to_fiscal_year": fiscal_year.get('name'), |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 67 | "period_start_date": year_start_date, |
| 68 | "period_end_date": year_end_date, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 69 | "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 Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 83 | "name": "Category-wise Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 84 | "chart_name": _("Category-wise Asset Value"), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 85 | "chart_type": "Report", |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 86 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 87 | "x_field": "asset_category", |
| 88 | "timeseries": 0, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 89 | "filters_json": json.dumps({ |
| 90 | "company": company, |
| 91 | "status":"In Location", |
| 92 | "group_by":"Asset Category", |
| 93 | "is_existing_asset":0 |
| 94 | }), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 95 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 116 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 117 | "x_field": "location", |
| 118 | "timeseries": 0, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 119 | "filters_json": json.dumps({ |
| 120 | "company": company, |
| 121 | "status":"In Location", |
| 122 | "group_by":"Location", |
| 123 | "is_existing_asset":0 |
| 124 | }), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 125 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 141 | } |
| 142 | ] |
| 143 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 144 | def get_number_cards(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 145 | return [ |
| 146 | { |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 147 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 171 | "name": "Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 172 | "label": _("Asset Value"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 173 | "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 Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 180 | "doctype": "Number Card" |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 181 | } |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 182 | ] |