blob: 291abb87b045e9c8c0e46a5129283e22e929df06 [file] [log] [blame]
marinationd99f85b2020-05-12 13:16:05 +05301# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4import frappe
5import json
marinationa74d4332020-05-15 23:37:48 +05306from frappe.utils import nowdate
7from erpnext.accounts.utils import get_fiscal_year
marinationd99f85b2020-05-12 13:16:05 +05308
9def get_data():
10 return frappe._dict({
11 "dashboards": get_dashboards(),
12 "charts": get_charts(),
13 "number_cards": get_number_cards(),
14 })
15
marination354b0162020-05-12 17:35:17 +053016def get_company_for_dashboards():
17 company = frappe.defaults.get_defaults().company
18 if company:
19 return company
20 else:
21 company_list = frappe.get_list("Company")
22 if company_list:
23 return company_list[0].name
24 return None
25
26company = frappe.get_doc("Company", get_company_for_dashboards())
marinationa74d4332020-05-15 23:37:48 +053027fiscal_year = get_fiscal_year(nowdate(), as_dict=1)
28fiscal_year_name = fiscal_year.get("name")
29start_date = str(fiscal_year.get("year_start_date"))
30end_date = str(fiscal_year.get("year_end_date"))
marination354b0162020-05-12 17:35:17 +053031
marinationd99f85b2020-05-12 13:16:05 +053032def get_dashboards():
33 return [{
marination354b0162020-05-12 17:35:17 +053034 "name": "Buying",
35 "dashboard_name": "Buying",
marinationd99f85b2020-05-12 13:16:05 +053036 "charts": [
marinationa74d4332020-05-15 23:37:48 +053037 { "chart": "Top Suppliers", "width": "Full"},
38 { "chart": "Material Request Analysis", "width": "Half"},
marination354b0162020-05-12 17:35:17 +053039 { "chart": "Purchase Order Analysis", "width": "Half"},
marinationa74d4332020-05-15 23:37:48 +053040 { "chart": "Purchase Order Trends", "width": "Full"}
41 ],
42 "cards": [
43 { "card": "Purchase Orders to Receive"},
44 { "card": "Purchase Order Expenses"},
45 { "card": "Active Suppliers"},
46 { "card": "Active Supplier Quotations"}
marinationd99f85b2020-05-12 13:16:05 +053047 ]
48 }]
49
50def get_charts():
marination354b0162020-05-12 17:35:17 +053051 return [
52 {
marination354b0162020-05-12 17:35:17 +053053 "name": "Purchase Order Analysis",
marination354b0162020-05-12 17:35:17 +053054 "chart_name": "Purchase Order Analysis",
marinationa74d4332020-05-15 23:37:48 +053055 "chart_type": "Report",
marination354b0162020-05-12 17:35:17 +053056 "custom_options": json.dumps({
57 "type": "donut",
58 "height": 300,
59 "axisOptions": {"shortenYAxisNumbers": 1}
marinationa74d4332020-05-15 23:37:48 +053060 }),
marination354b0162020-05-12 17:35:17 +053061 "doctype": "Dashboard Chart",
marination354b0162020-05-12 17:35:17 +053062 "filters_json": json.dumps({
63 "company": company.name,
marinationa74d4332020-05-15 23:37:48 +053064 "from_date": start_date,
65 "to_date": end_date
marination354b0162020-05-12 17:35:17 +053066 }),
67 "is_custom": 1,
marinationa74d4332020-05-15 23:37:48 +053068 "is_public": 1,
69 "owner": "Administrator",
70 "report_name": "Purchase Order Analysis",
71 "type": "Donut"
72 },
73 {
74 "name": "Material Request Analysis",
75 "chart_name": "Material Request Analysis",
76 "chart_type": "Group By",
77 "custom_options": json.dumps({"height": 300}),
78 "doctype": "Dashboard Chart",
79 "document_type": "Material Request",
80 "filters_json": json.dumps(
81 [["Material Request", "status", "not in", ["Draft", "Cancelled", "Stopped", None], False],
82 ["Material Request", "material_request_type", "=", "Purchase", False],
83 ["Material Request", "company", "=", company.name, False]]
84 ),
85 "group_by_based_on": "status",
86 "group_by_type": "Count",
87 "is_custom": 0,
88 "is_public": 1,
89 "number_of_groups": 0,
90 "owner": "Administrator",
91 "type": "Donut"
92 },
93 {
94 "name": "Purchase Order Trends",
95 "chart_name": "Purchase Order Trends",
marination354b0162020-05-12 17:35:17 +053096 "chart_type": "Report",
marination354b0162020-05-12 17:35:17 +053097 "custom_options": json.dumps({
marinationa74d4332020-05-15 23:37:48 +053098 "type": "line",
99 "regionFill": 1,
100 "axisOptions": {"shortenYAxisNumbers": 1},
101 "tooltipOptions": {}
102 }),
103 "doctype": "Dashboard Chart",
104 "filters_json": json.dumps({
105 "company": company.name,
106 "period": "Monthly",
107 "fiscal_year": fiscal_year_name,
108 "period_based_on": "posting_date",
109 "based_on": "Item"
110 }),
111 "is_custom": 1,
112 "is_public": 1,
113 "owner": "Administrator",
114 "report_name": "Purchase Order Trends",
115 "type": "Line"
116 },
117 {
118 "name": "Top Suppliers",
119 "chart_name": "Top Suppliers",
120 "chart_type": "Report",
121 "doctype": "Dashboard Chart",
122 "filters_json": json.dumps({
123 "company": company.name,
124 "period": "Monthly",
125 "fiscal_year": fiscal_year_name,
126 "period_based_on": "posting_date",
127 "based_on": "Supplier"
128 }),
129 "is_custom": 1,
130 "is_public": 1,
131 "owner": "Administrator",
132 "report_name": "Purchase Receipt Trends",
133 "type": "Bar"
marination354b0162020-05-12 17:35:17 +0530134 }
135 ]
marinationd99f85b2020-05-12 13:16:05 +0530136
137def get_number_cards():
marinationa74d4332020-05-15 23:37:48 +0530138 return [
139 {
140 "name": "Purchase Order Expenses",
141 "aggregate_function_based_on": "base_grand_total",
142 "doctype": "Number Card",
143 "document_type": "Purchase Order",
144 "filters_json": json.dumps(
145 [["Purchase Order", "transaction_date", "Between", [start_date,end_date], False],
146 ["Purchase Order", "status", "not in", ["Draft","On Hold","Cancelled","Closed", None], False],
147 ["Purchase Order", "company", "=", company.name, False]]
148 ),
149 "function": "Sum",
150 "is_public": 1,
151 "label": "Purchase Order Expenses",
152 "owner": "Administrator",
153 "show_percentage_stats": 1,
154 "stats_time_interval": "Monthly"
155 },
156 {
157 "name": "Purchase Orders to Receive",
158 "doctype": "Number Card",
159 "document_type": "Purchase Order",
160 "filters_json": json.dumps(
161 [["Purchase Order", "status", "in", ["To Receive and Bill", "To Receive", None], False],
162 ["Purchase Order", "company", "=", company.name, False]]
163 ),
164 "function": "Count",
165 "is_public": 1,
166 "label": "Purchase Orders to Receive",
167 "owner": "Administrator",
168 "show_percentage_stats": 1,
169 "stats_time_interval": "Weekly"
170 },
171 {
172 "name": "Active Suppliers",
173 "doctype": "Number Card",
174 "document_type": "Supplier",
175 "filters_json": json.dumps([["Supplier", "disabled", "=", "0"]]),
176 "function": "Count",
177 "is_public": 1,
178 "label": "Active Suppliers",
179 "owner": "Administrator",
180 "show_percentage_stats": 1,
181 "stats_time_interval": "Monthly"
182 },
183 {
184 "name": "Active Supplier Quotations",
185 "doctype": "Number Card",
186 "document_type": "Supplier Quotation",
187 "filters_json": json.dumps([["Supplier Quotation", "status", "=", "Submitted", False]]),
188 "function": "Count",
189 "is_public": 1,
190 "label": "Active Supplier Quotations",
191 "owner": "Administrator",
192 "show_percentage_stats": 1,
193 "stats_time_interval": "Monthly"
194 }
195 ]