blob: 901c0581f4c1f4634cd3344eb88dc6fc12cde117 [file] [log] [blame]
Anupam K79a8bd12020-05-10 23:36:33 +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
Nabin Hait7cbbd682020-05-20 12:55:34 +05305from frappe import _
Anupam K79a8bd12020-05-10 23:36:33 +05306
7def get_data():
8 return frappe._dict({
9 "dashboards": get_dashboards(),
10 "charts": get_charts(),
11 "number_cards": get_number_cards()
12 })
13
14def get_dashboards():
15 return [{
16 "doctype": "Dashboard",
17 "name": "CRM",
18 "dashboard_name": "CRM",
19 "charts": [
Nabin Hait7cbbd682020-05-20 12:55:34 +053020 { "chart": "Incoming Leads", "width": "Full" },
21 { "chart": "Opportunity Trends", "width": "Full"},
22 { "chart": "Won Opportunities", "width": "Full" },
23 { "chart": "Territory Wise Opportunity Count", "width": "Half"},
Nabin Hait7cbbd682020-05-20 12:55:34 +053024 { "chart": "Opportunities via Campaigns", "width": "Half" },
Anupam Kumarf1077102020-05-28 13:34:55 +053025 { "chart": "Territory Wise Sales", "width": "Full"},
Anupam K79a8bd12020-05-10 23:36:33 +053026 { "chart": "Lead Source", "width": "Half"}
27 ],
28 "cards": [
Nabin Hait7cbbd682020-05-20 12:55:34 +053029 { "card": "New Lead (Last 1 Month)" },
30 { "card": "New Opportunity (Last 1 Month)" },
31 { "card": "Won Opportunity (Last 1 Month)" },
32 { "card": "Open Opportunity"},
Anupam K79a8bd12020-05-10 23:36:33 +053033 ]
34 }]
35
36def get_company_for_dashboards():
37 company = frappe.defaults.get_defaults().company
38 if company:
39 return company
40 else:
41 company_list = frappe.get_list("Company")
42 if company_list:
43 return company_list[0].name
44 return None
45
46def get_charts():
47 company = get_company_for_dashboards()
48
49 return [{
Nabin Hait7cbbd682020-05-20 12:55:34 +053050 "name": "Incoming Leads",
Anupam K79a8bd12020-05-10 23:36:33 +053051 "doctype": "Dashboard Chart",
52 "time_interval": "Yearly",
53 "chart_type": "Count",
Nabin Hait7cbbd682020-05-20 12:55:34 +053054 "chart_name": _("Incoming Leads"),
Anupam K79a8bd12020-05-10 23:36:33 +053055 "timespan": "Last Quarter",
56 "time_interval": "Weekly",
57 "document_type": "Lead",
58 "based_on": "creation",
59 'is_public': 1,
60 'timeseries': 1,
61 "owner": "Administrator",
Anupam Kumarf1077102020-05-28 13:34:55 +053062 "filters_json": json.dumps([]),
Anupam K79a8bd12020-05-10 23:36:33 +053063 "type": "Bar"
64 },
65 {
Nabin Hait7cbbd682020-05-20 12:55:34 +053066 "name": "Opportunity Trends",
Anupam K79a8bd12020-05-10 23:36:33 +053067 "doctype": "Dashboard Chart",
68 "time_interval": "Yearly",
69 "chart_type": "Count",
Nabin Hait7cbbd682020-05-20 12:55:34 +053070 "chart_name": _("Opportunity Trends"),
Anupam K79a8bd12020-05-10 23:36:33 +053071 "timespan": "Last Quarter",
72 "time_interval": "Weekly",
73 "document_type": "Opportunity",
74 "based_on": "creation",
75 'is_public': 1,
76 'timeseries': 1,
77 "owner": "Administrator",
78 "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]),
79 "type": "Bar"
80 },
81 {
Nabin Hait7cbbd682020-05-20 12:55:34 +053082 "name": "Opportunities via Campaigns",
83 "chart_name": _("Opportunities via Campaigns"),
Anupam K79a8bd12020-05-10 23:36:33 +053084 "doctype": "Dashboard Chart",
Nabin Hait7cbbd682020-05-20 12:55:34 +053085 "chart_type": "Group By",
86 "group_by_type": "Count",
87 "group_by_based_on": "campaign",
88 "document_type": "Opportunity",
Anupam K79a8bd12020-05-10 23:36:33 +053089 'is_public': 1,
90 'timeseries': 1,
91 "owner": "Administrator",
92 "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]),
Anupam Kumarf1077102020-05-28 13:34:55 +053093 "type": "Pie",
94 "custom_options": json.dumps({
95 "truncateLegends": 1,
96 "maxSlices": 8
97 })
Anupam K79a8bd12020-05-10 23:36:33 +053098 },
99 {
Nabin Hait7cbbd682020-05-20 12:55:34 +0530100 "name": "Won Opportunities",
Anupam K79a8bd12020-05-10 23:36:33 +0530101 "doctype": "Dashboard Chart",
102 "time_interval": "Yearly",
103 "chart_type": "Count",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530104 "chart_name": _("Won Opportunities"),
Anupam K79a8bd12020-05-10 23:36:33 +0530105 "timespan": "Last Year",
106 "time_interval": "Monthly",
107 "document_type": "Opportunity",
108 "based_on": "modified",
109 'is_public': 1,
110 'timeseries': 1,
111 "owner": "Administrator",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530112 "filters_json": json.dumps([
113 ["Opportunity", "company", "=", company, False],
114 ["Opportunity", "status", "=", "Converted", False]]),
Anupam K79a8bd12020-05-10 23:36:33 +0530115 "type": "Bar"
116 },
117 {
Nabin Hait7cbbd682020-05-20 12:55:34 +0530118 "name": "Territory Wise Opportunity Count",
Anupam K79a8bd12020-05-10 23:36:33 +0530119 "doctype": "Dashboard Chart",
120 "chart_type": "Group By",
121 "group_by_type": "Count",
122 "group_by_based_on": "territory",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530123 "chart_name": _("Territory Wise Opportunity Count"),
Anupam K79a8bd12020-05-10 23:36:33 +0530124 "document_type": "Opportunity",
125 'is_public': 1,
Nabin Hait7cbbd682020-05-20 12:55:34 +0530126 "filters_json": json.dumps([
127 ["Opportunity", "company", "=", company, False]
128 ]),
Anupam K79a8bd12020-05-10 23:36:33 +0530129 "owner": "Administrator",
Anupam Kumarf1077102020-05-28 13:34:55 +0530130 "type": "Donut",
131 "custom_options": json.dumps({
132 "truncateLegends": 1,
133 "maxSlices": 8
134 })
Anupam K79a8bd12020-05-10 23:36:33 +0530135 },
136 {
137 "name": "Territory Wise Sales",
138 "doctype": "Dashboard Chart",
139 "chart_type": "Group By",
140 "group_by_type": "Sum",
141 "group_by_based_on": "territory",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530142 "chart_name": _("Territory Wise Sales"),
Anupam K79a8bd12020-05-10 23:36:33 +0530143 "aggregate_function_based_on": "opportunity_amount",
144 "document_type": "Opportunity",
145 'is_public': 1,
146 "owner": "Administrator",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530147 "filters_json": json.dumps([
148 ["Opportunity", "company", "=", company, False],
149 ["Opportunity", "status", "=", "Converted", False]
150 ]),
Anupam Kumarf1077102020-05-28 13:34:55 +0530151 "type": "Bar"
Anupam K79a8bd12020-05-10 23:36:33 +0530152 },
153 {
154 "name": "Lead Source",
155 "doctype": "Dashboard Chart",
156 "chart_type": "Group By",
157 "group_by_type": "Count",
158 "group_by_based_on": "source",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530159 "chart_name": _("Lead Source"),
Anupam K79a8bd12020-05-10 23:36:33 +0530160 "document_type": "Lead",
161 'is_public': 1,
162 "owner": "Administrator",
Anupam Kumarf1077102020-05-28 13:34:55 +0530163 "type": "Pie",
164 "custom_options": json.dumps({
165 "truncateLegends": 1,
166 "maxSlices": 8
167 })
Anupam K79a8bd12020-05-10 23:36:33 +0530168 }]
169
170def get_number_cards():
171 return [{
172 "doctype": "Number Card",
173 "document_type": "Lead",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530174 "name": "New Lead (Last 1 Month)",
Anupam Ke88f2bb2020-07-06 12:34:05 +0530175 "filters_json": json.dumps([
176 ["Lead", "creation", "Timespan", "last month"]
177 ]),
Anupam K79a8bd12020-05-10 23:36:33 +0530178 "function": "Count",
179 "is_public": 1,
Nabin Hait7cbbd682020-05-20 12:55:34 +0530180 "label": _("New Lead (Last 1 Month)"),
Anupam K79a8bd12020-05-10 23:36:33 +0530181 "show_percentage_stats": 1,
182 "stats_time_interval": "Daily"
183 },
184 {
185 "doctype": "Number Card",
186 "document_type": "Opportunity",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530187 "name": "New Opportunity (Last 1 Month)",
Anupam Ke88f2bb2020-07-06 12:34:05 +0530188 "filters_json": json.dumps([
189 ["Opportunity", "creation", "Timespan", "last month"]
190 ]),
Nabin Hait7cbbd682020-05-20 12:55:34 +0530191 "function": "Count",
192 "is_public": 1,
193 "label": _("New Opportunity (Last 1 Month)"),
194 "show_percentage_stats": 1,
195 "stats_time_interval": "Daily"
196 },
197 {
198 "doctype": "Number Card",
199 "document_type": "Opportunity",
200 "name": "Won Opportunity (Last 1 Month)",
Anupam Ke88f2bb2020-07-06 12:34:05 +0530201 "filters_json": json.dumps([
202 ["Opportunity", "status", "=", "Converted",False],
203 ["Opportunity", "creation", "Timespan", "last month"]
204 ]),
Nabin Hait7cbbd682020-05-20 12:55:34 +0530205 "function": "Count",
206 "is_public": 1,
207 "label": _("Won Opportunity (Last 1 Month)"),
208 "show_percentage_stats": 1,
209 "stats_time_interval": "Daily"
210 },
211 {
212 "doctype": "Number Card",
213 "document_type": "Opportunity",
214 "name": "Open Opportunity",
Anupam K79a8bd12020-05-10 23:36:33 +0530215 "filters_json": json.dumps([["Opportunity","status","=","Open",False]]),
216 "function": "Count",
217 "is_public": 1,
Nabin Hait7cbbd682020-05-20 12:55:34 +0530218 "label": _("Open Opportunity"),
Anupam K79a8bd12020-05-10 23:36:33 +0530219 "show_percentage_stats": 1,
220 "stats_time_interval": "Daily"
221 }]