marination | d99f85b | 2020-05-12 13:16:05 +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 |
| 6 | |
| 7 | |
| 8 | def get_data(): |
| 9 | return frappe._dict({ |
| 10 | "dashboards": get_dashboards(), |
| 11 | "charts": get_charts(), |
| 12 | "number_cards": get_number_cards(), |
| 13 | }) |
| 14 | |
marination | 354b016 | 2020-05-12 17:35:17 +0530 | [diff] [blame] | 15 | def get_company_for_dashboards(): |
| 16 | company = frappe.defaults.get_defaults().company |
| 17 | if company: |
| 18 | return company |
| 19 | else: |
| 20 | company_list = frappe.get_list("Company") |
| 21 | if company_list: |
| 22 | return company_list[0].name |
| 23 | return None |
| 24 | |
| 25 | company = frappe.get_doc("Company", get_company_for_dashboards()) |
| 26 | |
marination | d99f85b | 2020-05-12 13:16:05 +0530 | [diff] [blame] | 27 | def get_dashboards(): |
| 28 | return [{ |
marination | 354b016 | 2020-05-12 17:35:17 +0530 | [diff] [blame] | 29 | "name": "Buying", |
| 30 | "dashboard_name": "Buying", |
marination | d99f85b | 2020-05-12 13:16:05 +0530 | [diff] [blame] | 31 | "charts": [ |
marination | 354b016 | 2020-05-12 17:35:17 +0530 | [diff] [blame] | 32 | { "chart": "Purchase Analytics", "width": "Full"}, |
| 33 | { "chart": "Material Request Purchase Analysis", "width": "Half"}, |
| 34 | { "chart": "Purchase Order Analysis", "width": "Half"}, |
| 35 | { "chart": "Requested Items to Order", "width": "Full"} |
marination | d99f85b | 2020-05-12 13:16:05 +0530 | [diff] [blame] | 36 | ] |
| 37 | }] |
| 38 | |
| 39 | def get_charts(): |
marination | 354b016 | 2020-05-12 17:35:17 +0530 | [diff] [blame] | 40 | return [ |
| 41 | { |
| 42 | "name": "Purchase Analytics", |
| 43 | "doctype": "Dashboard Chart", |
| 44 | "owner": "Administrator", |
| 45 | "report_name": "Purchase Analytics", |
| 46 | "filters_json": json.dumps({ |
| 47 | "tree_type": "Item", |
| 48 | "doc_type": "Purchase Receipt", |
| 49 | "value_quantity": "Value", |
| 50 | "from_date": "2020-03-01", |
| 51 | "to_date": "2020-07-31", |
| 52 | "company": company.name, |
| 53 | "range": "Weekly" |
| 54 | }), |
| 55 | "x_field": "entity", |
| 56 | "type": "Bar", |
| 57 | 'timeseries': 0, |
| 58 | "chart_type": "Report", |
| 59 | "chart_name": "Purchase Analytics", |
| 60 | "custom_options": json.dumps({ |
| 61 | "x_field": "entity", |
| 62 | "chart_type": "Bar", |
| 63 | "y_axis_fields": [{"idx": 1, "__islocal": "true", "y_field": "total"}], |
| 64 | "y_fields": ["total"] |
| 65 | }) |
| 66 | }, |
| 67 | { |
| 68 | "name": "Material Request Purchase Analysis", |
| 69 | "doctype": "Dashboard Chart", |
| 70 | "owner": "Administrator", |
| 71 | "document_type": "Material Request", |
| 72 | "filters_json": '[["Material Request","status","not in",["Draft","Cancelled","Stopped",null],false],["Material Request","material_request_type","=","Purchase",false],["Material Request","company","=", "{company}", false]]'.format(company=company.name), |
| 73 | "is_custom": 0, |
| 74 | "type": "Donut", |
| 75 | "timeseries": 0, |
| 76 | "chart_type": "Group By", |
| 77 | "group_by_based_on": "status", |
| 78 | "chart_name": "Material Request Purchase Analysis", |
| 79 | "group_by_type": "Count", |
| 80 | "custom_options": json.dumps({"height": 300}) |
| 81 | |
| 82 | }, |
| 83 | { |
| 84 | "name": "Purchase Order Analysis", |
| 85 | "doctype": "Dashboard Chart", |
| 86 | "owner": "Administrator", |
| 87 | "report_name": "Purchase Order Analysis", |
| 88 | "filters_json": json.dumps({ |
| 89 | "company": company.name, |
| 90 | "from_date": "2020-04-04", |
| 91 | "to_date": "2020-07-04", |
| 92 | "chart_based_on": "Quantity" |
| 93 | }), |
| 94 | "is_custom": 1, |
| 95 | "type": "Donut", |
| 96 | "timeseries": 0, |
| 97 | "chart_type": "Report", |
| 98 | "chart_name": "Purchase Order Analysis", |
| 99 | "custom_options": json.dumps({ |
| 100 | "type": "donut", |
| 101 | "height": 300, |
| 102 | "axisOptions": {"shortenYAxisNumbers": 1} |
| 103 | }) |
| 104 | }, |
| 105 | { |
| 106 | "name": "Requested Items to Order", |
| 107 | "doctype": "Dashboard Chart", |
| 108 | "owner": "Administrator", |
| 109 | "report_name": "Requested Items to Order", |
| 110 | "filters_json": json.dumps({ |
| 111 | "company": company.name, |
| 112 | "from_date": "2020-04-01", |
| 113 | "to_date": "2020-07-01", |
| 114 | "group_by_mr": 0 |
| 115 | }), |
| 116 | "is_custom": 1, |
| 117 | "type": "Bar", |
| 118 | "timeseries": 0, |
| 119 | "chart_type": "Report", |
| 120 | "chart_name": "Requested Items to Order", |
| 121 | "custom_options": json.dumps({ |
| 122 | "type": "bar", |
| 123 | "barOptions": {"stacked": 1}, |
| 124 | "axisOptions": {"shortenYAxisNumbers": 1} |
| 125 | }) |
| 126 | } |
| 127 | ] |
marination | d99f85b | 2020-05-12 13:16:05 +0530 | [diff] [blame] | 128 | |
| 129 | def get_number_cards(): |
marination | 354b016 | 2020-05-12 17:35:17 +0530 | [diff] [blame] | 130 | return [{}] |