blob: 16904b34295777298cb6d232e2036af2f96f9b8b [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"},
Anupam K79a8bd12020-05-10 23:36:33 +053024 { "chart": "Territory Wise Sales", "width": "Half"},
Nabin Hait7cbbd682020-05-20 12:55:34 +053025 { "chart": "Opportunities via Campaigns", "width": "Half" },
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",
62 "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]),
63 "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]]),
Nabin Hait7cbbd682020-05-20 12:55:34 +053093 "type": "Pie"
Anupam K79a8bd12020-05-10 23:36:33 +053094 },
95 {
Nabin Hait7cbbd682020-05-20 12:55:34 +053096 "name": "Won Opportunities",
Anupam K79a8bd12020-05-10 23:36:33 +053097 "doctype": "Dashboard Chart",
98 "time_interval": "Yearly",
99 "chart_type": "Count",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530100 "chart_name": _("Won Opportunities"),
Anupam K79a8bd12020-05-10 23:36:33 +0530101 "timespan": "Last Year",
102 "time_interval": "Monthly",
103 "document_type": "Opportunity",
104 "based_on": "modified",
105 'is_public': 1,
106 'timeseries': 1,
107 "owner": "Administrator",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530108 "filters_json": json.dumps([
109 ["Opportunity", "company", "=", company, False],
110 ["Opportunity", "status", "=", "Converted", False]]),
Anupam K79a8bd12020-05-10 23:36:33 +0530111 "type": "Bar"
112 },
113 {
Nabin Hait7cbbd682020-05-20 12:55:34 +0530114 "name": "Territory Wise Opportunity Count",
Anupam K79a8bd12020-05-10 23:36:33 +0530115 "doctype": "Dashboard Chart",
116 "chart_type": "Group By",
117 "group_by_type": "Count",
118 "group_by_based_on": "territory",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530119 "chart_name": _("Territory Wise Opportunity Count"),
Anupam K79a8bd12020-05-10 23:36:33 +0530120 "document_type": "Opportunity",
121 'is_public': 1,
Nabin Hait7cbbd682020-05-20 12:55:34 +0530122 "filters_json": json.dumps([
123 ["Opportunity", "company", "=", company, False]
124 ]),
Anupam K79a8bd12020-05-10 23:36:33 +0530125 "owner": "Administrator",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530126 "type": "Donut"
Anupam K79a8bd12020-05-10 23:36:33 +0530127 },
128 {
129 "name": "Territory Wise Sales",
130 "doctype": "Dashboard Chart",
131 "chart_type": "Group By",
132 "group_by_type": "Sum",
133 "group_by_based_on": "territory",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530134 "chart_name": _("Territory Wise Sales"),
Anupam K79a8bd12020-05-10 23:36:33 +0530135 "aggregate_function_based_on": "opportunity_amount",
136 "document_type": "Opportunity",
137 'is_public': 1,
138 "owner": "Administrator",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530139 "filters_json": json.dumps([
140 ["Opportunity", "company", "=", company, False],
141 ["Opportunity", "status", "=", "Converted", False]
142 ]),
143 "type": "Donut"
Anupam K79a8bd12020-05-10 23:36:33 +0530144 },
145 {
146 "name": "Lead Source",
147 "doctype": "Dashboard Chart",
148 "chart_type": "Group By",
149 "group_by_type": "Count",
150 "group_by_based_on": "source",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530151 "chart_name": _("Lead Source"),
Anupam K79a8bd12020-05-10 23:36:33 +0530152 "document_type": "Lead",
153 'is_public': 1,
154 "owner": "Administrator",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530155 "type": "Pie"
Anupam K79a8bd12020-05-10 23:36:33 +0530156 }]
157
158def get_number_cards():
159 return [{
160 "doctype": "Number Card",
161 "document_type": "Lead",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530162 "name": "New Lead (Last 1 Month)",
163 "filters_json": json.dumps([["Lead","creation","Previous","1 month",False]]),
Anupam K79a8bd12020-05-10 23:36:33 +0530164 "function": "Count",
165 "is_public": 1,
Nabin Hait7cbbd682020-05-20 12:55:34 +0530166 "label": _("New Lead (Last 1 Month)"),
Anupam K79a8bd12020-05-10 23:36:33 +0530167 "show_percentage_stats": 1,
168 "stats_time_interval": "Daily"
169 },
170 {
171 "doctype": "Number Card",
172 "document_type": "Opportunity",
Nabin Hait7cbbd682020-05-20 12:55:34 +0530173 "name": "New Opportunity (Last 1 Month)",
174 "filters_json": json.dumps([["Opportunity","creation","Previous","1 month",False]]),
175 "function": "Count",
176 "is_public": 1,
177 "label": _("New Opportunity (Last 1 Month)"),
178 "show_percentage_stats": 1,
179 "stats_time_interval": "Daily"
180 },
181 {
182 "doctype": "Number Card",
183 "document_type": "Opportunity",
184 "name": "Won Opportunity (Last 1 Month)",
185 "filters_json": json.dumps([["Opportunity","creation","Previous","1 month",False]]),
186 "function": "Count",
187 "is_public": 1,
188 "label": _("Won Opportunity (Last 1 Month)"),
189 "show_percentage_stats": 1,
190 "stats_time_interval": "Daily"
191 },
192 {
193 "doctype": "Number Card",
194 "document_type": "Opportunity",
195 "name": "Open Opportunity",
Anupam K79a8bd12020-05-10 23:36:33 +0530196 "filters_json": json.dumps([["Opportunity","status","=","Open",False]]),
197 "function": "Count",
198 "is_public": 1,
Nabin Hait7cbbd682020-05-20 12:55:34 +0530199 "label": _("Open Opportunity"),
Anupam K79a8bd12020-05-10 23:36:33 +0530200 "show_percentage_stats": 1,
201 "stats_time_interval": "Daily"
202 }]