blob: 5b1ac9bf5e282f00b513eff053864dbc24f46c5c [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
5
6def get_data():
7 return frappe._dict({
8 "dashboards": get_dashboards(),
9 "charts": get_charts(),
10 "number_cards": get_number_cards()
11 })
12
13def get_dashboards():
14 return [{
15 "doctype": "Dashboard",
16 "name": "CRM",
17 "dashboard_name": "CRM",
18 "charts": [
19 { "chart": "Lead", "width": "Full" },
20 { "chart": "Opportunity", "width": "Full"},
21 { "chart": "Campaign", "width": "Half" },
22 { "chart": "Opportunities Won", "width": "Half" },
23 { "chart": "Territory Wise Opportunity", "width": "Half"},
24 { "chart": "Territory Wise Sales", "width": "Half"},
25 { "chart": "Qualified For Call", "width": "Full"},
26 { "chart": "Lead Source", "width": "Half"}
27 ],
28 "cards": [
29 { "card": "New Lead" },
30 { "card": "New Opportunity" },
31 { "card": "Won Opportunity" },
32 ]
33 }]
34
35def get_company_for_dashboards():
36 company = frappe.defaults.get_defaults().company
37 if company:
38 return company
39 else:
40 company_list = frappe.get_list("Company")
41 if company_list:
42 return company_list[0].name
43 return None
44
45def get_charts():
46 company = get_company_for_dashboards()
47
48 return [{
49 "name": "Lead",
50 "doctype": "Dashboard Chart",
51 "time_interval": "Yearly",
52 "chart_type": "Count",
53 "chart_name": "Lead",
54 "timespan": "Last Quarter",
55 "time_interval": "Weekly",
56 "document_type": "Lead",
57 "based_on": "creation",
58 'is_public': 1,
59 'timeseries': 1,
60 "owner": "Administrator",
61 "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]),
62 "type": "Bar"
63 },
64 {
65 "name": "Opportunity",
66 "doctype": "Dashboard Chart",
67 "time_interval": "Yearly",
68 "chart_type": "Count",
69 "chart_name": "Opportunity",
70 "timespan": "Last Quarter",
71 "time_interval": "Weekly",
72 "document_type": "Opportunity",
73 "based_on": "creation",
74 'is_public': 1,
75 'timeseries': 1,
76 "owner": "Administrator",
77 "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]),
78 "type": "Bar"
79 },
80 {
81 "name": "Campaign",
82 "doctype": "Dashboard Chart",
83 "time_interval": "Yearly",
84 "chart_type": "Count",
85 "chart_name": "Campaign",
86 "timespan": "Last Year",
87 "time_interval": "Monthly",
88 "document_type": "Campaign",
89 "based_on": "creation",
90 'is_public': 1,
91 'timeseries': 1,
92 "owner": "Administrator",
93 "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]),
94 "type": "Line",
95 "color": "#428b46"
96 },
97 {
98 "name": "Opportunities Won",
99 "doctype": "Dashboard Chart",
100 "time_interval": "Yearly",
101 "chart_type": "Count",
102 "chart_name": "Opportunities Won",
103 "timespan": "Last Year",
104 "time_interval": "Monthly",
105 "document_type": "Opportunity",
106 "based_on": "modified",
107 'is_public': 1,
108 'timeseries': 1,
109 "owner": "Administrator",
110 "filters_json": json.dumps([["Opportunity", "company", "=", company, False],["Opportunity", "sales_stage", "=", "Converted", False]]),
111 "type": "Bar"
112 },
113 {
114 "name": "Territory Wise Opportunity",
115 "doctype": "Dashboard Chart",
116 "chart_type": "Group By",
117 "group_by_type": "Count",
118 "group_by_based_on": "territory",
119 "chart_name": "Territory Wise Opportunity",
120 "document_type": "Opportunity",
121 'is_public': 1,
122 "owner": "Administrator",
123 "type": "Line"
124 },
125 {
126 "name": "Territory Wise Sales",
127 "doctype": "Dashboard Chart",
128 "chart_type": "Group By",
129 "group_by_type": "Sum",
130 "group_by_based_on": "territory",
131 "chart_name": "Territory Wise Sales",
132 "aggregate_function_based_on": "opportunity_amount",
133 "document_type": "Opportunity",
134 'is_public': 1,
135 "owner": "Administrator",
136 "filters_json": json.dumps([["Opportunity", "company", "=", company, False],["Opportunity", "sales_stage", "=", "Converted", False]]),
137 "type": "Bar",
138 "color": "#7575ff"
139 },
140 {
141 "name": "Qualified For Call",
142 "doctype": "Dashboard Chart",
143 "time_interval": "Yearly",
144 "chart_type": "Count",
145 "chart_name": "Qualified For Call",
146 "timespan": "Last Quarter",
147 "time_interval": "Weekly",
148 "document_type": "Opportunity",
149 "based_on": "modified",
150 'is_public': 1,
151 'timeseries': 1,
152 "owner": "Administrator",
153 "filters_json": json.dumps([["Opportunity", "company", "=", company, False],["Opportunity", "sales_stage", "=", "Qualification", False]]),
154 "type": "Line",
155 "color": "#fff168"
156 },
157 {
158 "name": "Lead Source",
159 "doctype": "Dashboard Chart",
160 "chart_type": "Group By",
161 "group_by_type": "Count",
162 "group_by_based_on": "source",
163 "chart_name": "Lead Source",
164 "document_type": "Lead",
165 'is_public': 1,
166 "owner": "Administrator",
167 "type": "Donut"
168 }]
169
170def get_number_cards():
171 return [{
172 "doctype": "Number Card",
173 "document_type": "Lead",
174 "name": "New Lead",
175 "filters_json": json.dumps([["Lead","status","=","Lead",False]]),
176 "function": "Count",
177 "is_public": 1,
178 "label": "New Lead",
179 "show_percentage_stats": 1,
180 "stats_time_interval": "Daily"
181 },
182 {
183 "doctype": "Number Card",
184 "document_type": "Opportunity",
185 "name": "New Opportunity",
186 "filters_json": json.dumps([["Opportunity","status","=","Open",False]]),
187 "function": "Count",
188 "is_public": 1,
189 "label": "New Opportunity",
190 "show_percentage_stats": 1,
191 "stats_time_interval": "Daily"
192 },
193 {
194 "doctype": "Number Card",
195 "document_type": "Opportunity",
196 "name": "Won Opportunity",
197 "filters_json": json.dumps([["Opportunity","status","=","Converted",False]]),
198 "function": "Count",
199 "is_public": 1,
200 "label": "Won Opportunity",
201 "show_percentage_stats": 1,
202 "stats_time_interval": "Daily"
203 }]