blob: ef61f230acdd9cd0a90116660c6a3d91674ec335 [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 _
Nabin Haitf2fb9362020-05-19 12:32:39 +05306from frappe.utils import nowdate, get_date_str
7from erpnext.accounts.utils import get_fiscal_year
Rohit Waghchaure366bce62020-05-06 02:38:27 +05308
9def get_data():
10 return frappe._dict({
11 "dashboards": get_dashboards(),
12 "charts": get_charts(),
13 "number_cards": get_number_cards(),
14 })
15
16def get_dashboards():
17 return [{
rohitwaghchaure65c90952020-05-19 15:54:24 +053018 "name": "Manufacturing",
19 "dashboard_name": "Manufacturing",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053020 "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": [
31 { "card": "Total Work Order" },
32 { "card": "Completed Work Order" },
33 { "card": "Ongoing Job Card" },
34 { "card": "Total Quality Inspection"}
35 ]
36 }]
37
38def 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 Haitf2fb9362020-05-19 12:32:39 +053046 "based_on": "modified",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053047 "time_interval": "Yearly",
48 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053049 "chart_name": _("Produced Quantity"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053050 "name": "Produced Quantity",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053051 "document_type": "Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +053052 "filters_json": json.dumps([['Work Order', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053053 "group_by_type": "Count",
Nabin Haitf2fb9362020-05-19 12:32:39 +053054 "time_interval": "Monthly",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053055 "timespan": "Last Year",
56 "owner": "Administrator",
57 "type": "Line",
Nabin Haitf2fb9362020-05-19 12:32:39 +053058 "value_based_on": "produced_qty",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053059 "is_public": 1,
60 "timeseries": 1
61 }, {
62 "doctype": "Dashboard Chart",
63 "based_on": "creation",
64 "time_interval": "Yearly",
65 "chart_type": "Sum",
Nabin Haitf2fb9362020-05-19 12:32:39 +053066 "chart_name": _("Completed Operation"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053067 "name": "Completed Operation",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053068 "document_type": "Work Order Operation",
Nabin Haitf2fb9362020-05-19 12:32:39 +053069 "filters_json": json.dumps([['Work Order Operation', 'docstatus', '=', 1, False]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +053070 "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 Haitf2fb9362020-05-19 12:32:39 +053082 "chart_name": _("Work Order Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +053083 "name": "Work Order Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +053084 "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 Haitf2fb9362020-05-19 12:32:39 +0530101 "chart_name": _("Quality Inspection Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530102 "name": "Quality Inspection Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530103 "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 Haitf2fb9362020-05-19 12:32:39 +0530120 "chart_name": _("Pending Work Order"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530121 "name": "Pending Work Order",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530122 "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 Haitf2fb9362020-05-19 12:32:39 +0530139 "chart_name": _("Last Month Downtime Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530140 "name": "Last Month Downtime Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530141 "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 Haitf2fb9362020-05-19 12:32:39 +0530153 "name": "Work Order Qty Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530154 "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 Haitf2fb9362020-05-19 12:32:39 +0530168 "chart_name": _("Job Card Analysis"),
Rohit Waghchaure1c9210b2020-05-14 18:58:25 +0530169 "name": "Job Card Analysis",
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530170 "timespan": "Last Year",
171 "report_name": "Job Card Summary",
172 "owner": "Administrator",
173 "is_public": 1,
174 "is_custom": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530175 "filters_json": json.dumps({"company": company, "docstatus": 1, "range":"Monthly"}),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530176 "custom_options": json.dumps({
177 "barOptions": { "stacked": 1 }
178 }),
179 "type": "Bar"
180 }]
181
182def get_number_cards():
Nabin Haitf2fb9362020-05-19 12:32:39 +0530183 fiscal_year = get_fiscal_year(date=nowdate())
184 year_start_date = get_date_str(fiscal_year[1])
185 year_end_date = get_date_str(fiscal_year[2])
186
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530187 return [{
188 "doctype": "Number Card",
189 "document_type": "Work Order",
190 "name": "Total Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530191 "filters_json": json.dumps([
192 ['Work Order', 'docstatus', '=', 1],
193 ['Work Order', 'creation', 'between', [year_start_date, year_end_date]]
194 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530195 "function": "Count",
196 "is_public": 1,
197 "label": _("Total Work Order"),
198 "show_percentage_stats": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530199 "stats_time_interval": "Monthly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530200 },
201 {
202 "doctype": "Number Card",
203 "document_type": "Work Order",
204 "name": "Completed Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530205 "filters_json": json.dumps([
206 ['Work Order', 'status', '=', 'Completed'],
207 ['Work Order', 'docstatus', '=', 1],
208 ['Work Order', 'creation', 'between', [year_start_date, year_end_date]]
209 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530210 "function": "Count",
211 "is_public": 1,
212 "label": _("Completed Work Order"),
213 "show_percentage_stats": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530214 "stats_time_interval": "Monthly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530215 },
216 {
217 "doctype": "Number Card",
218 "document_type": "Job Card",
219 "name": "Ongoing Job Card",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530220 "filters_json": json.dumps([
221 ['Job Card', 'status','!=','Completed'],
222 ['Job Card', 'docstatus', '=', 1]
223 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530224 "function": "Count",
225 "is_public": 1,
226 "label": _("Ongoing Job Card"),
227 "show_percentage_stats": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530228 "stats_time_interval": "Monthly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530229 },
230 {
231 "doctype": "Number Card",
232 "document_type": "Quality Inspection",
233 "name": "Total Quality Inspection",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530234 "filters_json": json.dumps([['Quality Inspection', 'docstatus', '=', 1]]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530235 "function": "Count",
236 "is_public": 1,
237 "label": _("Total Quality Inspection"),
238 "show_percentage_stats": 1,
Nabin Haitf2fb9362020-05-19 12:32:39 +0530239 "stats_time_interval": "Monthly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530240 }]