blob: 7ba43d6471e342b7f4e1c6f5bcfe78989d43956e [file] [log] [blame]
Rohit Waghchaure366bce62020-05-06 02:38:27 +05301# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4import frappe, erpnext, json
5from frappe import _
Rohit Waghchaure1e04b452020-05-26 23:07:11 +05306from frappe.utils import nowdate, get_first_day, get_last_day, add_months
Rohit Waghchaure366bce62020-05-06 02:38:27 +05307
8def get_data():
9 return frappe._dict({
10 "dashboards": get_dashboards(),
11 "charts": get_charts(),
12 "number_cards": get_number_cards(),
13 })
14
15def get_dashboards():
16 return [{
rohitwaghchaure65c90952020-05-19 15:54:24 +053017 "name": "Manufacturing",
18 "dashboard_name": "Manufacturing",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053019 "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 Waghchaure1e04b452020-05-26 23:07:11 +053030 { "card": "Monthly Total Work Order" },
31 { "card": "Monthly Completed Work Order" },
Rohit Waghchaure366bce62020-05-06 02:38:27 +053032 { "card": "Ongoing Job Card" },
Rohit Waghchaure1e04b452020-05-26 23:07:11 +053033 { "card": "Monthly Quality Inspection"}
Rohit Waghchaure366bce62020-05-06 02:38:27 +053034 ]
35 }]
36
37def 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 Haitf2fb9362020-05-19 12:32:39 +053045 "based_on": "modified",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053046 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053047 "chart_name": _("Produced Quantity"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053048 "name": "Produced Quantity",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053049 "document_type": "Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +053050 "filters_json": json.dumps([['Work Order', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053051 "group_by_type": "Count",
Nabin Haitf2fb9362020-05-19 12:32:39 +053052 "time_interval": "Monthly",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053053 "timespan": "Last Year",
54 "owner": "Administrator",
55 "type": "Line",
Nabin Haitf2fb9362020-05-19 12:32:39 +053056 "value_based_on": "produced_qty",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053057 "is_public": 1,
58 "timeseries": 1
59 }, {
60 "doctype": "Dashboard Chart",
61 "based_on": "creation",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053062 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053063 "chart_name": _("Completed Operation"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053064 "name": "Completed Operation",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053065 "document_type": "Work Order Operation",
Nabin Haitf2fb9362020-05-19 12:32:39 +053066 "filters_json": json.dumps([['Work Order Operation', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053067 "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 Haitf2fb9362020-05-19 12:32:39 +053079 "chart_name": _("Work Order Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053080 "name": "Work Order Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053081 "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 Haitf2fb9362020-05-19 12:32:39 +053098 "chart_name": _("Quality Inspection Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053099 "name": "Quality Inspection Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530100 "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 Haitf2fb9362020-05-19 12:32:39 +0530117 "chart_name": _("Pending Work Order"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530118 "name": "Pending Work Order",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530119 "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 Haitf2fb9362020-05-19 12:32:39 +0530136 "chart_name": _("Last Month Downtime Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530137 "name": "Last Month Downtime Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530138 "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 Haitf2fb9362020-05-19 12:32:39 +0530150 "name": "Work Order Qty Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530151 "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 Haitf2fb9362020-05-19 12:32:39 +0530165 "chart_name": _("Job Card Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530166 "name": "Job Card Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530167 "timespan": "Last Year",
168 "report_name": "Job Card Summary",
169 "owner": "Administrator",
170 "is_public": 1,
171 "is_custom": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530172 "filters_json": json.dumps({"company": company, "docstatus": 1, "range":"Monthly"}),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530173 "custom_options": json.dumps({
174 "barOptions": { "stacked": 1 }
175 }),
176 "type": "Bar"
177 }]
178
179def get_number_cards():
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530180 start_date = add_months(nowdate(), -1)
181 end_date = nowdate()
Nabin Haitf2fb9362020-05-19 12:32:39 +0530182
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530183 return [{
184 "doctype": "Number Card",
185 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530186 "name": "Monthly Total Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530187 "filters_json": json.dumps([
188 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530189 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530190 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530191 "function": "Count",
192 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530193 "label": _("Monthly Total Work Orders"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530194 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530195 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530196 },
197 {
198 "doctype": "Number Card",
199 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530200 "name": "Monthly Completed Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530201 "filters_json": json.dumps([
202 ['Work Order', 'status', '=', 'Completed'],
203 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530204 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530205 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530206 "function": "Count",
207 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530208 "label": _("Monthly Completed Work Orders"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530209 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530210 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530211 },
212 {
213 "doctype": "Number Card",
214 "document_type": "Job Card",
215 "name": "Ongoing Job Card",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530216 "filters_json": json.dumps([
217 ['Job Card', 'status','!=','Completed'],
218 ['Job Card', 'docstatus', '=', 1]
219 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530220 "function": "Count",
221 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530222 "label": _("Ongoing Job Cards"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530223 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530224 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530225 },
226 {
227 "doctype": "Number Card",
228 "document_type": "Quality Inspection",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530229 "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 Waghchaure366bce62020-05-06 02:38:27 +0530234 "function": "Count",
235 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530236 "label": _("Monthly Quality Inspections"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530237 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530238 "stats_time_interval": "Weekly"
Ankush Menatdedf2c12021-04-17 14:57:57 +0530239 }]