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