Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +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, erpnext, json |
| 5 | from frappe import _ |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 6 | from frappe.utils import nowdate, get_first_day, get_last_day, add_months |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 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 | |
| 15 | def get_dashboards(): |
| 16 | return [{ |
rohitwaghchaure | 65c9095 | 2020-05-19 15:54:24 +0530 | [diff] [blame] | 17 | "name": "Manufacturing", |
| 18 | "dashboard_name": "Manufacturing", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 19 | "charts": [ |
| 20 | { "chart": "Produced Quantity", "width": "Half" }, |
| 21 | { "chart": "Completed Operation", "width": "Half" }, |
| 22 | { "chart": "Work Order Analysis", "width": "Half" }, |
| 23 | { "chart": "Quality Inspection Analysis", "width": "Half" }, |
| 24 | { "chart": "Pending Work Order", "width": "Half" }, |
| 25 | { "chart": "Last Month Downtime Analysis", "width": "Half" }, |
| 26 | { "chart": "Work Order Qty Analysis", "width": "Full" }, |
| 27 | { "chart": "Job Card Analysis", "width": "Full" } |
| 28 | ], |
| 29 | "cards": [ |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 30 | { "card": "Monthly Total Work Order" }, |
| 31 | { "card": "Monthly Completed Work Order" }, |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 32 | { "card": "Ongoing Job Card" }, |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 33 | { "card": "Monthly Quality Inspection"} |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 34 | ] |
| 35 | }] |
| 36 | |
| 37 | def get_charts(): |
| 38 | company = erpnext.get_default_company() |
| 39 | |
| 40 | if not company: |
| 41 | company = frappe.db.get_value("Company", {"is_group": 0}, "name") |
| 42 | |
| 43 | return [{ |
| 44 | "doctype": "Dashboard Chart", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 45 | "based_on": "modified", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 46 | "time_interval": "Yearly", |
| 47 | "chart_type": "Sum", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 48 | "chart_name": _("Produced Quantity"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 49 | "name": "Produced Quantity", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 50 | "document_type": "Work Order", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 51 | "filters_json": json.dumps([['Work Order', 'docstatus', '=', 1, False]]), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 52 | "group_by_type": "Count", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 53 | "time_interval": "Monthly", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 54 | "timespan": "Last Year", |
| 55 | "owner": "Administrator", |
| 56 | "type": "Line", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 57 | "value_based_on": "produced_qty", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 58 | "is_public": 1, |
| 59 | "timeseries": 1 |
| 60 | }, { |
| 61 | "doctype": "Dashboard Chart", |
| 62 | "based_on": "creation", |
| 63 | "time_interval": "Yearly", |
| 64 | "chart_type": "Sum", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 65 | "chart_name": _("Completed Operation"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 66 | "name": "Completed Operation", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 67 | "document_type": "Work Order Operation", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 68 | "filters_json": json.dumps([['Work Order Operation', 'docstatus', '=', 1, False]]), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 69 | "group_by_type": "Count", |
| 70 | "time_interval": "Quarterly", |
| 71 | "timespan": "Last Year", |
| 72 | "owner": "Administrator", |
| 73 | "type": "Line", |
| 74 | "value_based_on": "completed_qty", |
| 75 | "is_public": 1, |
| 76 | "timeseries": 1 |
| 77 | }, { |
| 78 | "doctype": "Dashboard Chart", |
| 79 | "time_interval": "Yearly", |
| 80 | "chart_type": "Report", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 81 | "chart_name": _("Work Order Analysis"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 82 | "name": "Work Order Analysis", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 83 | "timespan": "Last Year", |
| 84 | "report_name": "Work Order Summary", |
| 85 | "owner": "Administrator", |
| 86 | "filters_json": json.dumps({"company": company, "charts_based_on": "Status"}), |
| 87 | "type": "Donut", |
| 88 | "is_public": 1, |
| 89 | "is_custom": 1, |
| 90 | "custom_options": json.dumps({ |
| 91 | "axisOptions": { |
| 92 | "shortenYAxisNumbers": 1 |
| 93 | }, |
| 94 | "height": 300 |
| 95 | }), |
| 96 | }, { |
| 97 | "doctype": "Dashboard Chart", |
| 98 | "time_interval": "Yearly", |
| 99 | "chart_type": "Report", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 100 | "chart_name": _("Quality Inspection Analysis"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 101 | "name": "Quality Inspection Analysis", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 102 | "timespan": "Last Year", |
| 103 | "report_name": "Quality Inspection Summary", |
| 104 | "owner": "Administrator", |
| 105 | "filters_json": json.dumps({}), |
| 106 | "type": "Donut", |
| 107 | "is_public": 1, |
| 108 | "is_custom": 1, |
| 109 | "custom_options": json.dumps({ |
| 110 | "axisOptions": { |
| 111 | "shortenYAxisNumbers": 1 |
| 112 | }, |
| 113 | "height": 300 |
| 114 | }), |
| 115 | }, { |
| 116 | "doctype": "Dashboard Chart", |
| 117 | "time_interval": "Yearly", |
| 118 | "chart_type": "Report", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 119 | "chart_name": _("Pending Work Order"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 120 | "name": "Pending Work Order", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 121 | "timespan": "Last Year", |
| 122 | "report_name": "Work Order Summary", |
| 123 | "filters_json": json.dumps({"company": company, "charts_based_on": "Age"}), |
| 124 | "owner": "Administrator", |
| 125 | "type": "Donut", |
| 126 | "is_public": 1, |
| 127 | "is_custom": 1, |
| 128 | "custom_options": json.dumps({ |
| 129 | "axisOptions": { |
| 130 | "shortenYAxisNumbers": 1 |
| 131 | }, |
| 132 | "height": 300 |
| 133 | }), |
| 134 | }, { |
| 135 | "doctype": "Dashboard Chart", |
| 136 | "time_interval": "Yearly", |
| 137 | "chart_type": "Report", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 138 | "chart_name": _("Last Month Downtime Analysis"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 139 | "name": "Last Month Downtime Analysis", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 140 | "timespan": "Last Year", |
| 141 | "filters_json": json.dumps({}), |
| 142 | "report_name": "Downtime Analysis", |
| 143 | "owner": "Administrator", |
| 144 | "is_public": 1, |
| 145 | "is_custom": 1, |
| 146 | "type": "Bar" |
| 147 | }, { |
| 148 | "doctype": "Dashboard Chart", |
| 149 | "time_interval": "Yearly", |
| 150 | "chart_type": "Report", |
| 151 | "chart_name": _("Work Order Qty Analysis"), |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 152 | "name": "Work Order Qty Analysis", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 153 | "timespan": "Last Year", |
| 154 | "report_name": "Work Order Summary", |
| 155 | "filters_json": json.dumps({"company": company, "charts_based_on": "Quantity"}), |
| 156 | "owner": "Administrator", |
| 157 | "type": "Bar", |
| 158 | "is_public": 1, |
| 159 | "is_custom": 1, |
| 160 | "custom_options": json.dumps({ |
| 161 | "barOptions": { "stacked": 1 } |
| 162 | }), |
| 163 | }, { |
| 164 | "doctype": "Dashboard Chart", |
| 165 | "time_interval": "Yearly", |
| 166 | "chart_type": "Report", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 167 | "chart_name": _("Job Card Analysis"), |
Rohit Waghchaure | 1c9210b | 2020-05-14 18:58:25 +0530 | [diff] [blame] | 168 | "name": "Job Card Analysis", |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 169 | "timespan": "Last Year", |
| 170 | "report_name": "Job Card Summary", |
| 171 | "owner": "Administrator", |
| 172 | "is_public": 1, |
| 173 | "is_custom": 1, |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 174 | "filters_json": json.dumps({"company": company, "docstatus": 1, "range":"Monthly"}), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 175 | "custom_options": json.dumps({ |
| 176 | "barOptions": { "stacked": 1 } |
| 177 | }), |
| 178 | "type": "Bar" |
| 179 | }] |
| 180 | |
| 181 | def get_number_cards(): |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 182 | start_date = add_months(nowdate(), -1) |
| 183 | end_date = nowdate() |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 184 | |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 185 | return [{ |
| 186 | "doctype": "Number Card", |
| 187 | "document_type": "Work Order", |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 188 | "name": "Monthly Total Work Order", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 189 | "filters_json": json.dumps([ |
| 190 | ['Work Order', 'docstatus', '=', 1], |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 191 | ['Work Order', 'creation', 'between', [start_date, end_date]] |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 192 | ]), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 193 | "function": "Count", |
| 194 | "is_public": 1, |
rohitwaghchaure | 7056cd3 | 2020-06-30 08:20:03 +0530 | [diff] [blame] | 195 | "label": _("Monthly Total Work Orders"), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 196 | "show_percentage_stats": 1, |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 197 | "stats_time_interval": "Weekly" |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 198 | }, |
| 199 | { |
| 200 | "doctype": "Number Card", |
| 201 | "document_type": "Work Order", |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 202 | "name": "Monthly Completed Work Order", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 203 | "filters_json": json.dumps([ |
| 204 | ['Work Order', 'status', '=', 'Completed'], |
| 205 | ['Work Order', 'docstatus', '=', 1], |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 206 | ['Work Order', 'creation', 'between', [start_date, end_date]] |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 207 | ]), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 208 | "function": "Count", |
| 209 | "is_public": 1, |
rohitwaghchaure | 7056cd3 | 2020-06-30 08:20:03 +0530 | [diff] [blame] | 210 | "label": _("Monthly Completed Work Orders"), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 211 | "show_percentage_stats": 1, |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 212 | "stats_time_interval": "Weekly" |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 213 | }, |
| 214 | { |
| 215 | "doctype": "Number Card", |
| 216 | "document_type": "Job Card", |
| 217 | "name": "Ongoing Job Card", |
Nabin Hait | f2fb936 | 2020-05-19 12:32:39 +0530 | [diff] [blame] | 218 | "filters_json": json.dumps([ |
| 219 | ['Job Card', 'status','!=','Completed'], |
| 220 | ['Job Card', 'docstatus', '=', 1] |
| 221 | ]), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 222 | "function": "Count", |
| 223 | "is_public": 1, |
rohitwaghchaure | 7056cd3 | 2020-06-30 08:20:03 +0530 | [diff] [blame] | 224 | "label": _("Ongoing Job Cards"), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 225 | "show_percentage_stats": 1, |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 226 | "stats_time_interval": "Weekly" |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 227 | }, |
| 228 | { |
| 229 | "doctype": "Number Card", |
| 230 | "document_type": "Quality Inspection", |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 231 | "name": "Monthly Quality Inspection", |
| 232 | "filters_json": json.dumps([ |
| 233 | ['Quality Inspection', 'docstatus', '=', 1], |
| 234 | ['Quality Inspection', 'creation', 'between', [start_date, end_date]] |
| 235 | ]), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 236 | "function": "Count", |
| 237 | "is_public": 1, |
rohitwaghchaure | 7056cd3 | 2020-06-30 08:20:03 +0530 | [diff] [blame] | 238 | "label": _("Monthly Quality Inspections"), |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 239 | "show_percentage_stats": 1, |
Rohit Waghchaure | 1e04b45 | 2020-05-26 23:07:11 +0530 | [diff] [blame] | 240 | "stats_time_interval": "Weekly" |
Rohit Waghchaure | 366bce6 | 2020-05-06 02:38:27 +0530 | [diff] [blame] | 241 | }] |