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"}, |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 24 | { "chart": "Territory Wise Sales", "width": "Half"}, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 25 | { "chart": "Opportunities via Campaigns", "width": "Half" }, |
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", |
| 62 | "filters_json": json.dumps([["Opportunity", "company", "=", company, False]]), |
| 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]]), |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 93 | "type": "Pie" |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 94 | }, |
| 95 | { |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 96 | "name": "Won Opportunities", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 97 | "doctype": "Dashboard Chart", |
| 98 | "time_interval": "Yearly", |
| 99 | "chart_type": "Count", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 100 | "chart_name": _("Won Opportunities"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 101 | "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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 108 | "filters_json": json.dumps([ |
| 109 | ["Opportunity", "company", "=", company, False], |
| 110 | ["Opportunity", "status", "=", "Converted", False]]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 111 | "type": "Bar" |
| 112 | }, |
| 113 | { |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 114 | "name": "Territory Wise Opportunity Count", |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 115 | "doctype": "Dashboard Chart", |
| 116 | "chart_type": "Group By", |
| 117 | "group_by_type": "Count", |
| 118 | "group_by_based_on": "territory", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 119 | "chart_name": _("Territory Wise Opportunity Count"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 120 | "document_type": "Opportunity", |
| 121 | 'is_public': 1, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 122 | "filters_json": json.dumps([ |
| 123 | ["Opportunity", "company", "=", company, False] |
| 124 | ]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 125 | "owner": "Administrator", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 126 | "type": "Donut" |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 127 | }, |
| 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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 134 | "chart_name": _("Territory Wise Sales"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 135 | "aggregate_function_based_on": "opportunity_amount", |
| 136 | "document_type": "Opportunity", |
| 137 | 'is_public': 1, |
| 138 | "owner": "Administrator", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 139 | "filters_json": json.dumps([ |
| 140 | ["Opportunity", "company", "=", company, False], |
| 141 | ["Opportunity", "status", "=", "Converted", False] |
| 142 | ]), |
| 143 | "type": "Donut" |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 144 | }, |
| 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 Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 151 | "chart_name": _("Lead Source"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 152 | "document_type": "Lead", |
| 153 | 'is_public': 1, |
| 154 | "owner": "Administrator", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 155 | "type": "Pie" |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 156 | }] |
| 157 | |
| 158 | def get_number_cards(): |
| 159 | return [{ |
| 160 | "doctype": "Number Card", |
| 161 | "document_type": "Lead", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 162 | "name": "New Lead (Last 1 Month)", |
| 163 | "filters_json": json.dumps([["Lead","creation","Previous","1 month",False]]), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 164 | "function": "Count", |
| 165 | "is_public": 1, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 166 | "label": _("New Lead (Last 1 Month)"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 167 | "show_percentage_stats": 1, |
| 168 | "stats_time_interval": "Daily" |
| 169 | }, |
| 170 | { |
| 171 | "doctype": "Number Card", |
| 172 | "document_type": "Opportunity", |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 173 | "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 K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 196 | "filters_json": json.dumps([["Opportunity","status","=","Open",False]]), |
| 197 | "function": "Count", |
| 198 | "is_public": 1, |
Nabin Hait | 7cbbd68 | 2020-05-20 12:55:34 +0530 | [diff] [blame] | 199 | "label": _("Open Opportunity"), |
Anupam K | 79a8bd1 | 2020-05-10 23:36:33 +0530 | [diff] [blame] | 200 | "show_percentage_stats": 1, |
| 201 | "stats_time_interval": "Daily" |
| 202 | }] |