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 | |
| 4 | import frappe |
| 5 | import json |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 6 | from frappe.utils import nowdate, add_months, get_date_str |
| 7 | from frappe import _ |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 8 | from erpnext.accounts.dashboard_fixtures import _get_fiscal_year |
| 9 | from erpnext.buying.dashboard_fixtures import get_company_for_dashboards |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 10 | |
| 11 | def get_data(): |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 12 | |
| 13 | fiscal_year = _get_fiscal_year(nowdate()) |
| 14 | |
| 15 | if not fiscal_year: |
| 16 | return frappe._dict() |
| 17 | |
Deepesh Garg | 7e974c9 | 2020-06-12 15:29:40 +0530 | [diff] [blame] | 18 | 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 Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 20 | |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 21 | return frappe._dict({ |
| 22 | "dashboards": get_dashboards(), |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 23 | "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 Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 25 | }) |
| 26 | |
| 27 | def get_dashboards(): |
| 28 | return [{ |
| 29 | "name": "Asset", |
| 30 | "dashboard_name": "Asset", |
| 31 | "charts": [ |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 32 | { "chart": "Asset Value Analytics", "width": "Full" }, |
| 33 | { "chart": "Category-wise Asset Value", "width": "Half" }, |
| 34 | { "chart": "Location-wise Asset Value", "width": "Half" }, |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 35 | ], |
| 36 | "cards": [ |
| 37 | {"card": "Total Assets"}, |
| 38 | {"card": "New Assets (This Year)"}, |
| 39 | {"card": "Asset Value"} |
| 40 | ] |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 41 | }] |
| 42 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 43 | def get_charts(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 44 | company = get_company_for_dashboards() |
Saqib Ansari | 22aec57 | 2020-05-08 16:39:17 +0530 | [diff] [blame] | 45 | return [ |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 46 | { |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 47 | "name": "Asset Value Analytics", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 48 | "chart_name": _("Asset Value Analytics"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 49 | "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 Garg | 7e974c9 | 2020-06-12 15:29:40 +0530 | [diff] [blame] | 62 | "from_fiscal_year": fiscal_year.get('name'), |
| 63 | "to_fiscal_year": fiscal_year.get('name'), |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 64 | "period_start_date": year_start_date, |
| 65 | "period_end_date": year_end_date, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 66 | "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 Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 80 | "name": "Category-wise Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 81 | "chart_name": _("Category-wise Asset Value"), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 82 | "chart_type": "Report", |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 83 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 84 | "x_field": "asset_category", |
| 85 | "timeseries": 0, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 86 | "filters_json": json.dumps({ |
| 87 | "company": company, |
| 88 | "status":"In Location", |
| 89 | "group_by":"Asset Category", |
| 90 | "is_existing_asset":0 |
| 91 | }), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 92 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 113 | "report_name": "Fixed Asset Register", |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 114 | "x_field": "location", |
| 115 | "timeseries": 0, |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 116 | "filters_json": json.dumps({ |
| 117 | "company": company, |
| 118 | "status":"In Location", |
| 119 | "group_by":"Location", |
| 120 | "is_existing_asset":0 |
| 121 | }), |
Saqib Ansari | ecddf33 | 2020-05-11 15:12:11 +0530 | [diff] [blame] | 122 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 138 | } |
| 139 | ] |
| 140 | |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 141 | def get_number_cards(fiscal_year, year_start_date, year_end_date): |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 142 | return [ |
| 143 | { |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 144 | "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 Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 168 | "name": "Asset Value", |
Nabin Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 169 | "label": _("Asset Value"), |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 170 | "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 Hait | 054aafa | 2020-05-20 18:21:51 +0530 | [diff] [blame] | 177 | "doctype": "Number Card" |
Saqib Ansari | 8990697 | 2020-05-12 17:38:34 +0530 | [diff] [blame] | 178 | } |
Deepesh Garg | 9df4532 | 2020-06-11 21:33:43 +0530 | [diff] [blame] | 179 | ] |