blob: 4a17fd07fbbb7c288e8f6855d48194cc1195da0a [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
Nabin Haitf2fb9362020-05-19 12:32:39 +05307from 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": [
Rohit Waghchaure1e04b452020-05-26 23:07:11 +053031 { "card": "Monthly Total Work Order" },
32 { "card": "Monthly Completed Work Order" },
Rohit Waghchaure366bce62020-05-06 02:38:27 +053033 { "card": "Ongoing Job Card" },
Rohit Waghchaure1e04b452020-05-26 23:07:11 +053034 { "card": "Monthly Quality Inspection"}
Rohit Waghchaure366bce62020-05-06 02:38:27 +053035 ]
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():
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530183 start_date = add_months(nowdate(), -1)
184 end_date = nowdate()
Nabin Haitf2fb9362020-05-19 12:32:39 +0530185
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530186 return [{
187 "doctype": "Number Card",
188 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530189 "name": "Monthly Total Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530190 "filters_json": json.dumps([
191 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530192 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530193 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530194 "function": "Count",
195 "is_public": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530196 "label": _("Monthly Total Work Order"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530197 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530198 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530199 },
200 {
201 "doctype": "Number Card",
202 "document_type": "Work Order",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530203 "name": "Monthly Completed Work Order",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530204 "filters_json": json.dumps([
205 ['Work Order', 'status', '=', 'Completed'],
206 ['Work Order', 'docstatus', '=', 1],
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530207 ['Work Order', 'creation', 'between', [start_date, end_date]]
Nabin Haitf2fb9362020-05-19 12:32:39 +0530208 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530209 "function": "Count",
210 "is_public": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530211 "label": _("Monthly Completed Work Order"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530212 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530213 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530214 },
215 {
216 "doctype": "Number Card",
217 "document_type": "Job Card",
218 "name": "Ongoing Job Card",
Nabin Haitf2fb9362020-05-19 12:32:39 +0530219 "filters_json": json.dumps([
220 ['Job Card', 'status','!=','Completed'],
221 ['Job Card', 'docstatus', '=', 1]
222 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530223 "function": "Count",
224 "is_public": 1,
225 "label": _("Ongoing Job Card"),
226 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530227 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530228 },
229 {
230 "doctype": "Number Card",
231 "document_type": "Quality Inspection",
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530232 "name": "Monthly Quality Inspection",
233 "filters_json": json.dumps([
234 ['Quality Inspection', 'docstatus', '=', 1],
235 ['Quality Inspection', 'creation', 'between', [start_date, end_date]]
236 ]),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530237 "function": "Count",
238 "is_public": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530239 "label": _("Monthly Quality Inspection"),
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530240 "show_percentage_stats": 1,
Rohit Waghchaure1e04b452020-05-26 23:07:11 +0530241 "stats_time_interval": "Weekly"
Rohit Waghchaure366bce62020-05-06 02:38:27 +0530242 }]