Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 1 | # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | import frappe, erpnext, json |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 5 | from frappe import _ |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 6 | |
| 7 | def get_data(): |
| 8 | return frappe._dict({ |
| 9 | "dashboards": get_dashboards(), |
| 10 | "charts": get_charts(), |
| 11 | "number_cards": get_number_cards() |
| 12 | }) |
| 13 | |
| 14 | def get_dashboards(): |
| 15 | return [{ |
| 16 | "doctype": "Dashboard", |
| 17 | "name": "CRM", |
| 18 | "dashboard_name": "CRM", |
| 19 | "charts": [ |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 20 | { "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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 24 | { "chart": "Opportunities via Campaigns", "width": "Half" }, |
Anupam Kumar | f107710 | 2020-05-28 13:34:55 +0530 | [diff] [blame] | 25 | { "chart": "Territory Wise Sales", "width": "Full"}, |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 26 | { "chart": "Lead Source", "width": "Half"} |
| 27 | ], |
| 28 | "cards": [ |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 29 | { "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 K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 33 | ] |
| 34 | }] |
| 35 | |
| 36 | def 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 | |
| 46 | def get_charts(): |
| 47 | company = get_company_for_dashboards() |
| 48 | |
| 49 | return [{ |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 50 | "name": "Incoming Leads", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 51 | "doctype": "Dashboard Chart", |
| 52 | "time_interval": "Yearly", |
| 53 | "chart_type": "Count", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 54 | "chart_name": _("Incoming Leads"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 55 | "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 Kumar | f107710 | 2020-05-28 13:34:55 +0530 | [diff] [blame] | 62 | "filters_json": json.dumps([]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 63 | "type": "Bar" |
| 64 | }, |
| 65 | { |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 66 | "name": "Opportunity Trends", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 67 | "doctype": "Dashboard Chart", |
| 68 | "time_interval": "Yearly", |
| 69 | "chart_type": "Count", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 70 | "chart_name": _("Opportunity Trends"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 71 | "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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 82 | "name": "Opportunities via Campaigns", |
| 83 | "chart_name": _("Opportunities via Campaigns"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 84 | "doctype": "Dashboard Chart", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 85 | "chart_type": "Group By", |
| 86 | "group_by_type": "Count", |
| 87 | "group_by_based_on": "campaign", |
| 88 | "document_type": "Opportunity", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 89 | 'is_public': 1, |
| 90 | 'timeseries': 1, |
| 91 | "owner": "Administrator", |
| 92 | "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]), |
Anupam Kumar | f107710 | 2020-05-28 13:34:55 +0530 | [diff] [blame] | 93 | "type": "Pie", |
| 94 | "custom_options": json.dumps({ |
| 95 | "truncateLegends": 1, |
| 96 | "maxSlices": 8 |
| 97 | }) |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 98 | }, |
| 99 | { |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 100 | "name": "Won Opportunities", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 101 | "doctype": "Dashboard Chart", |
| 102 | "time_interval": "Yearly", |
| 103 | "chart_type": "Count", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 104 | "chart_name": _("Won Opportunities"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 105 | "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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 112 | "filters_json": json.dumps([ |
| 113 | ["Opportunity", "company", "=", company, False], |
| 114 | ["Opportunity", "status", "=", "Converted", False]]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 115 | "type": "Bar" |
| 116 | }, |
| 117 | { |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 118 | "name": "Territory Wise Opportunity Count", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 119 | "doctype": "Dashboard Chart", |
| 120 | "chart_type": "Group By", |
| 121 | "group_by_type": "Count", |
| 122 | "group_by_based_on": "territory", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 123 | "chart_name": _("Territory Wise Opportunity Count"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 124 | "document_type": "Opportunity", |
| 125 | 'is_public': 1, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 126 | "filters_json": json.dumps([ |
| 127 | ["Opportunity", "company", "=", company, False] |
| 128 | ]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 129 | "owner": "Administrator", |
Anupam Kumar | f107710 | 2020-05-28 13:34:55 +0530 | [diff] [blame] | 130 | "type": "Donut", |
| 131 | "custom_options": json.dumps({ |
| 132 | "truncateLegends": 1, |
| 133 | "maxSlices": 8 |
| 134 | }) |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 135 | }, |
| 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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 142 | "chart_name": _("Territory Wise Sales"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 143 | "aggregate_function_based_on": "opportunity_amount", |
| 144 | "document_type": "Opportunity", |
| 145 | 'is_public': 1, |
| 146 | "owner": "Administrator", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 147 | "filters_json": json.dumps([ |
| 148 | ["Opportunity", "company", "=", company, False], |
| 149 | ["Opportunity", "status", "=", "Converted", False] |
| 150 | ]), |
Anupam Kumar | f107710 | 2020-05-28 13:34:55 +0530 | [diff] [blame] | 151 | "type": "Bar" |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 152 | }, |
| 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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 159 | "chart_name": _("Lead Source"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 160 | "document_type": "Lead", |
| 161 | 'is_public': 1, |
| 162 | "owner": "Administrator", |
Anupam Kumar | f107710 | 2020-05-28 13:34:55 +0530 | [diff] [blame] | 163 | "type": "Pie", |
| 164 | "custom_options": json.dumps({ |
| 165 | "truncateLegends": 1, |
| 166 | "maxSlices": 8 |
| 167 | }) |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 168 | }] |
| 169 | |
| 170 | def get_number_cards(): |
| 171 | return [{ |
| 172 | "doctype": "Number Card", |
| 173 | "document_type": "Lead", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 174 | "name": "New Lead (Last 1 Month)", |
Anupam K | e88f2bb | 2020-07-06 12:34:05 +0530 | [diff] [blame] | 175 | "filters_json": json.dumps([ |
| 176 | ["Lead", "creation", "Timespan", "last month"] |
| 177 | ]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 178 | "function": "Count", |
| 179 | "is_public": 1, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 180 | "label": _("New Lead (Last 1 Month)"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 181 | "show_percentage_stats": 1, |
| 182 | "stats_time_interval": "Daily" |
| 183 | }, |
| 184 | { |
| 185 | "doctype": "Number Card", |
| 186 | "document_type": "Opportunity", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 187 | "name": "New Opportunity (Last 1 Month)", |
Anupam K | e88f2bb | 2020-07-06 12:34:05 +0530 | [diff] [blame] | 188 | "filters_json": json.dumps([ |
| 189 | ["Opportunity", "creation", "Timespan", "last month"] |
| 190 | ]), |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 191 | "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 K | e88f2bb | 2020-07-06 12:34:05 +0530 | [diff] [blame] | 201 | "filters_json": json.dumps([ |
| 202 | ["Opportunity", "status", "=", "Converted",False], |
| 203 | ["Opportunity", "creation", "Timespan", "last month"] |
| 204 | ]), |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 205 | "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 K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 215 | "filters_json": json.dumps([["Opportunity","status","=","Open",False]]), |
| 216 | "function": "Count", |
| 217 | "is_public": 1, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 218 | "label": _("Open Opportunity"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 219 | "show_percentage_stats": 1, |
| 220 | "stats_time_interval": "Daily" |
| 221 | }] |