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