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