blob: 1bc12ff35ebab483e91254b1fe3d1b0587686df2 [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():
14 return frappe._dict({
15 "dashboards": get_dashboards(),
16 "charts": get_charts(),
17 "number_cards": get_number_cards(),
18 })
19
20def get_dashboards():
21 return [{
rohitwaghchaure65c90952020-05-19 15:54:24 +053022 "name": "Manufacturing",
23 "dashboard_name": "Manufacturing",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053024 "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 Waghchaure1e04b452020-05-26 23:07:11 +053035 { "card": "Monthly Total Work Order" },
36 { "card": "Monthly Completed Work Order" },
Rohit Waghchaure366bce62020-05-06 02:38:27 +053037 { "card": "Ongoing Job Card" },
Rohit Waghchaure1e04b452020-05-26 23:07:11 +053038 { "card": "Monthly Quality Inspection"}
Rohit Waghchaure366bce62020-05-06 02:38:27 +053039 ]
40 }]
41
42def 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 Haitf2fb9362020-05-19 12:32:39 +053050 "based_on": "modified",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053051 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053052 "chart_name": _("Produced Quantity"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053053 "name": "Produced Quantity",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053054 "document_type": "Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +053055 "filters_json": json.dumps([['Work Order', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053056 "group_by_type": "Count",
Nabin Haitf2fb9362020-05-19 12:32:39 +053057 "time_interval": "Monthly",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053058 "timespan": "Last Year",
59 "owner": "Administrator",
60 "type": "Line",
Nabin Haitf2fb9362020-05-19 12:32:39 +053061 "value_based_on": "produced_qty",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053062 "is_public": 1,
63 "timeseries": 1
64 }, {
65 "doctype": "Dashboard Chart",
66 "based_on": "creation",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053067 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053068 "chart_name": _("Completed Operation"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053069 "name": "Completed Operation",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053070 "document_type": "Work Order Operation",
Nabin Haitf2fb9362020-05-19 12:32:39 +053071 "filters_json": json.dumps([['Work Order Operation', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053072 "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 Haitf2fb9362020-05-19 12:32:39 +053084 "chart_name": _("Work Order Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053085 "name": "Work Order Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053086 "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 Haitf2fb9362020-05-19 12:32:39 +0530103 "chart_name": _("Quality Inspection Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530104 "name": "Quality Inspection Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530105 "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 Haitf2fb9362020-05-19 12:32:39 +0530122 "chart_name": _("Pending Work Order"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530123 "name": "Pending Work Order",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530124 "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 Haitf2fb9362020-05-19 12:32:39 +0530141 "chart_name": _("Last Month Downtime Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530142 "name": "Last Month Downtime Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530143 "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 Haitf2fb9362020-05-19 12:32:39 +0530155 "name": "Work Order Qty Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530156 "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 Haitf2fb9362020-05-19 12:32:39 +0530170 "chart_name": _("Job Card Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530171 "name": "Job Card Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530172 "timespan": "Last Year",
173 "report_name": "Job Card Summary",
174 "owner": "Administrator",
175 "is_public": 1,
176 "is_custom": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530177 "filters_json": json.dumps({"company": company, "docstatus": 1, "range":"Monthly"}),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530178 "custom_options": json.dumps({
179 "barOptions": { "stacked": 1 }
180 }),
181 "type": "Bar"
182 }]
183
184def get_number_cards():
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530185 start_date = add_months(nowdate(), -1)
186 end_date = nowdate()
Nabin Haitf2fb9362020-05-19 12:32:39 +0530187
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530188 return [{
189 "doctype": "Number Card",
190 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530191 "name": "Monthly Total Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530192 "filters_json": json.dumps([
193 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530194 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530195 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530196 "function": "Count",
197 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530198 "label": _("Monthly Total Work Orders"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530199 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530200 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530201 },
202 {
203 "doctype": "Number Card",
204 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530205 "name": "Monthly Completed Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530206 "filters_json": json.dumps([
207 ['Work Order', 'status', '=', 'Completed'],
208 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530209 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530210 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530211 "function": "Count",
212 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530213 "label": _("Monthly Completed Work Orders"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530214 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530215 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530216 },
217 {
218 "doctype": "Number Card",
219 "document_type": "Job Card",
220 "name": "Ongoing Job Card",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530221 "filters_json": json.dumps([
222 ['Job Card', 'status','!=','Completed'],
223 ['Job Card', 'docstatus', '=', 1]
224 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530225 "function": "Count",
226 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530227 "label": _("Ongoing Job Cards"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530228 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530229 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530230 },
231 {
232 "doctype": "Number Card",
233 "document_type": "Quality Inspection",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530234 "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 Waghchaure366bce62020-05-06 02:38:27 +0530239 "function": "Count",
240 "is_public": 1,
rohitwaghchaure7056cd32020-06-30 08:20:03 +0530241 "label": _("Monthly Quality Inspections"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530242 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530243 "stats_time_interval": "Weekly"
Ankush Menatdedf2c12021-04-17 14:57:57 +0530244 }]