blob: 0e9a21c02688374008f5bca0e022c7fda184c8f8 [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 "time_interval": "Yearly",
47 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053048 "chart_name": _("Produced Quantity"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053049 "name": "Produced Quantity",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053050 "document_type": "Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +053051 "filters_json": json.dumps([['Work Order', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053052 "group_by_type": "Count",
Nabin Haitf2fb9362020-05-19 12:32:39 +053053 "time_interval": "Monthly",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053054 "timespan": "Last Year",
55 "owner": "Administrator",
56 "type": "Line",
Nabin Haitf2fb9362020-05-19 12:32:39 +053057 "value_based_on": "produced_qty",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053058 "is_public": 1,
59 "timeseries": 1
60 }, {
61 "doctype": "Dashboard Chart",
62 "based_on": "creation",
63 "time_interval": "Yearly",
64 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053065 "chart_name": _("Completed Operation"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053066 "name": "Completed Operation",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053067 "document_type": "Work Order Operation",
Nabin Haitf2fb9362020-05-19 12:32:39 +053068 "filters_json": json.dumps([['Work Order Operation', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053069 "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 Haitf2fb9362020-05-19 12:32:39 +053081 "chart_name": _("Work Order Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053082 "name": "Work Order Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053083 "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 Haitf2fb9362020-05-19 12:32:39 +0530100 "chart_name": _("Quality Inspection Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530101 "name": "Quality Inspection Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530102 "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 Haitf2fb9362020-05-19 12:32:39 +0530119 "chart_name": _("Pending Work Order"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530120 "name": "Pending Work Order",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530121 "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 Haitf2fb9362020-05-19 12:32:39 +0530138 "chart_name": _("Last Month Downtime Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530139 "name": "Last Month Downtime Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530140 "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 Haitf2fb9362020-05-19 12:32:39 +0530152 "name": "Work Order Qty Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530153 "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 Haitf2fb9362020-05-19 12:32:39 +0530167 "chart_name": _("Job Card Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530168 "name": "Job Card Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530169 "timespan": "Last Year",
170 "report_name": "Job Card Summary",
171 "owner": "Administrator",
172 "is_public": 1,
173 "is_custom": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530174 "filters_json": json.dumps({"company": company, "docstatus": 1, "range":"Monthly"}),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530175 "custom_options": json.dumps({
176 "barOptions": { "stacked": 1 }
177 }),
178 "type": "Bar"
179 }]
180
181def get_number_cards():
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530182 start_date = add_months(nowdate(), -1)
183 end_date = nowdate()
Nabin Haitf2fb9362020-05-19 12:32:39 +0530184
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530185 return [{
186 "doctype": "Number Card",
187 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530188 "name": "Monthly Total Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530189 "filters_json": json.dumps([
190 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530191 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530192 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530193 "function": "Count",
194 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530195 "label": _("Monthly Total Work Orders"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530196 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530197 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530198 },
199 {
200 "doctype": "Number Card",
201 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530202 "name": "Monthly Completed Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530203 "filters_json": json.dumps([
204 ['Work Order', 'status', '=', 'Completed'],
205 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530206 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530207 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530208 "function": "Count",
209 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530210 "label": _("Monthly Completed Work Orders"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530211 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530212 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530213 },
214 {
215 "doctype": "Number Card",
216 "document_type": "Job Card",
217 "name": "Ongoing Job Card",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530218 "filters_json": json.dumps([
219 ['Job Card', 'status','!=','Completed'],
220 ['Job Card', 'docstatus', '=', 1]
221 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530222 "function": "Count",
223 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530224 "label": _("Ongoing Job Cards"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530225 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530226 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530227 },
228 {
229 "doctype": "Number Card",
230 "document_type": "Quality Inspection",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530231 "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 Waghchaure366bce62020-05-06 02:38:27 +0530236 "function": "Count",
237 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530238 "label": _("Monthly Quality Inspections"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530239 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530240 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530241 }]