blob: abb858f1f667bb4200623a17b7aa9066e3b64514 [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": [
marination50d4bf52020-05-19 17:02:47 +053037 { "chart": "Purchase Order Trends", "width": "Full"},
marinationa74d4332020-05-15 23:37:48 +053038 { "chart": "Material Request Analysis", "width": "Half"},
marination354b0162020-05-12 17:35:17 +053039 { "chart": "Purchase Order Analysis", "width": "Half"},
marination50d4bf52020-05-19 17:02:47 +053040 { "chart": "Top Suppliers", "width": "Full"}
marinationa74d4332020-05-15 23:37:48 +053041 ],
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],
marination50d4bf52020-05-19 17:02:47 +053083 ["Material Request", "company", "=", company.name, False],
84 ["Material Request", "transaction_date", "Between", [start_date,end_date], False]]
marinationa74d4332020-05-15 23:37:48 +053085 ),
86 "group_by_based_on": "status",
87 "group_by_type": "Count",
88 "is_custom": 0,
89 "is_public": 1,
90 "number_of_groups": 0,
91 "owner": "Administrator",
92 "type": "Donut"
93 },
94 {
95 "name": "Purchase Order Trends",
96 "chart_name": "Purchase Order Trends",
marination354b0162020-05-12 17:35:17 +053097 "chart_type": "Report",
marination354b0162020-05-12 17:35:17 +053098 "custom_options": json.dumps({
marinationa74d4332020-05-15 23:37:48 +053099 "type": "line",
marinationa74d4332020-05-15 23:37:48 +0530100 "axisOptions": {"shortenYAxisNumbers": 1},
marination50d4bf52020-05-19 17:02:47 +0530101 "tooltipOptions": {},
102 "lineOptions": {
103 "regionFill": 1
104 }
marinationa74d4332020-05-15 23:37:48 +0530105 }),
106 "doctype": "Dashboard Chart",
107 "filters_json": json.dumps({
108 "company": company.name,
109 "period": "Monthly",
110 "fiscal_year": fiscal_year_name,
111 "period_based_on": "posting_date",
112 "based_on": "Item"
113 }),
114 "is_custom": 1,
115 "is_public": 1,
116 "owner": "Administrator",
117 "report_name": "Purchase Order Trends",
118 "type": "Line"
119 },
120 {
121 "name": "Top Suppliers",
122 "chart_name": "Top Suppliers",
123 "chart_type": "Report",
124 "doctype": "Dashboard Chart",
125 "filters_json": json.dumps({
126 "company": company.name,
127 "period": "Monthly",
128 "fiscal_year": fiscal_year_name,
129 "period_based_on": "posting_date",
130 "based_on": "Supplier"
131 }),
132 "is_custom": 1,
133 "is_public": 1,
134 "owner": "Administrator",
135 "report_name": "Purchase Receipt Trends",
136 "type": "Bar"
marination354b0162020-05-12 17:35:17 +0530137 }
138 ]
marinationd99f85b2020-05-12 13:16:05 +0530139
140def get_number_cards():
marinationa74d4332020-05-15 23:37:48 +0530141 return [
142 {
143 "name": "Purchase Order Expenses",
144 "aggregate_function_based_on": "base_grand_total",
145 "doctype": "Number Card",
146 "document_type": "Purchase Order",
147 "filters_json": json.dumps(
148 [["Purchase Order", "transaction_date", "Between", [start_date,end_date], False],
149 ["Purchase Order", "status", "not in", ["Draft","On Hold","Cancelled","Closed", None], False],
marination50d4bf52020-05-19 17:02:47 +0530150 ["Purchase Order", "company", "=", company.name, False],
151 ["Purchase Order", "transaction_date", "Between", [start_date,end_date], False]]
marinationa74d4332020-05-15 23:37:48 +0530152 ),
153 "function": "Sum",
154 "is_public": 1,
155 "label": "Purchase Order Expenses",
156 "owner": "Administrator",
157 "show_percentage_stats": 1,
158 "stats_time_interval": "Monthly"
159 },
160 {
161 "name": "Purchase Orders to Receive",
162 "doctype": "Number Card",
163 "document_type": "Purchase Order",
164 "filters_json": json.dumps(
165 [["Purchase Order", "status", "in", ["To Receive and Bill", "To Receive", None], False],
marination50d4bf52020-05-19 17:02:47 +0530166 ["Purchase Order", "company", "=", company.name, False],
167 ["Purchase Order", "transaction_date", "Between", [start_date,end_date], False]]
marinationa74d4332020-05-15 23:37:48 +0530168 ),
169 "function": "Count",
170 "is_public": 1,
171 "label": "Purchase Orders to Receive",
172 "owner": "Administrator",
173 "show_percentage_stats": 1,
174 "stats_time_interval": "Weekly"
175 },
176 {
177 "name": "Active Suppliers",
178 "doctype": "Number Card",
179 "document_type": "Supplier",
180 "filters_json": json.dumps([["Supplier", "disabled", "=", "0"]]),
181 "function": "Count",
182 "is_public": 1,
183 "label": "Active Suppliers",
184 "owner": "Administrator",
185 "show_percentage_stats": 1,
186 "stats_time_interval": "Monthly"
187 },
188 {
189 "name": "Active Supplier Quotations",
190 "doctype": "Number Card",
191 "document_type": "Supplier Quotation",
192 "filters_json": json.dumps([["Supplier Quotation", "status", "=", "Submitted", False]]),
193 "function": "Count",
194 "is_public": 1,
195 "label": "Active Supplier Quotations",
196 "owner": "Administrator",
197 "show_percentage_stats": 1,
198 "stats_time_interval": "Monthly"
199 }
200 ]