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