marination | be5c45a | 2020-05-15 13:21:58 +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 |
| 5 | import json |
| 6 | from frappe.utils import nowdate |
| 7 | from erpnext.accounts.utils import get_fiscal_year |
| 8 | |
| 9 | def get_data(): |
| 10 | return frappe._dict({ |
| 11 | "dashboards": get_dashboards(), |
| 12 | "charts": get_charts(), |
| 13 | "number_cards": get_number_cards(), |
| 14 | }) |
| 15 | |
| 16 | def get_company_for_dashboards(): |
| 17 | company = frappe.defaults.get_defaults().company |
| 18 | if company: |
| 19 | return company |
| 20 | else: |
| 21 | company_list = frappe.get_list("Company") |
| 22 | if company_list: |
| 23 | return company_list[0].name |
| 24 | return None |
| 25 | |
| 26 | company = frappe.get_doc("Company", get_company_for_dashboards()) |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 27 | fiscal_year = get_fiscal_year(nowdate(), as_dict=1) |
| 28 | fiscal_year_name = fiscal_year.get("name") |
| 29 | start_date = str(fiscal_year.get("year_start_date")) |
| 30 | end_date = str(fiscal_year.get("year_end_date")) |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 31 | |
| 32 | def get_dashboards(): |
| 33 | return [{ |
| 34 | "name": "Stock", |
| 35 | "dashboard_name": "Stock", |
| 36 | "charts": [ |
| 37 | { "chart": "Item Shortage Summary", "width": "Half"}, |
| 38 | { "chart": "Stock Ageing", "width": "Half"}, |
| 39 | { "chart": "Item Wise Annual Revenue", "width": "Half"}, |
| 40 | { "chart": "Item Wise Annual Expenditure", "width": "Half"}, |
| 41 | { "chart": "Warehouse wise Stock Value", "width": "Full"} |
| 42 | ], |
| 43 | "cards": [ |
| 44 | { "card": "Purchase Receipts to Bill"}, |
| 45 | { "card": "Amount Payable against Receipt"}, |
| 46 | { "card": "Delivery Notes to Bill"}, |
| 47 | { "card": "Amount Receivable against Delivery"} |
| 48 | ] |
| 49 | }] |
| 50 | |
| 51 | def get_charts(): |
| 52 | return [ |
| 53 | { |
| 54 | "name": "Item Shortage Summary", |
| 55 | "chart_name": "Item Shortage Summary", |
| 56 | "chart_type": "Report", |
| 57 | "doctype": "Dashboard Chart", |
| 58 | "filters_json": json.dumps({ |
| 59 | "company": company.name |
| 60 | }), |
| 61 | "is_custom": 1, |
| 62 | "is_public": 1, |
| 63 | "owner": "Administrator", |
| 64 | "report_name": "Item Shortage Report", |
| 65 | "type": "Bar" |
| 66 | }, |
| 67 | { |
| 68 | "name": "Stock Ageing", |
| 69 | "chart_name": "Stock Ageing", |
| 70 | "chart_type": "Report", |
| 71 | "custom_options": json.dumps({ |
| 72 | "colors": ["#5e64ff"] |
| 73 | }), |
| 74 | "doctype": "Dashboard Chart", |
| 75 | "filters_json": json.dumps({ |
| 76 | "company": company.name, |
| 77 | "to_date": nowdate(), |
| 78 | "show_warehouse_wise_stock": 0 |
| 79 | }), |
| 80 | "is_custom": 1, |
| 81 | "is_public": 1, |
| 82 | "owner": "Administrator", |
| 83 | "report_name": "Stock Ageing", |
| 84 | "type": "Bar" |
| 85 | }, |
| 86 | { |
| 87 | "name": "Item Wise Annual Revenue", |
| 88 | "chart_name": "Item Wise Annual Revenue", |
| 89 | "chart_type": "Report", |
| 90 | "custom_options": json.dumps({ |
| 91 | "axisOptions": {"shortenYAxisNumbers": 1}, |
| 92 | "tooltipOptions": {}, |
| 93 | "colors":["#5e64ff"] |
| 94 | }), |
| 95 | "doctype": "Dashboard Chart", |
| 96 | "filters_json": json.dumps({ |
| 97 | "period": "Monthly", |
| 98 | "based_on": "Item", |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 99 | "fiscal_year": fiscal_year_name, |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 100 | "company": company.name |
| 101 | }), |
| 102 | "is_custom": 1, |
| 103 | "is_public": 1, |
| 104 | "owner": "Administrator", |
| 105 | "report_name": "Delivery Note Trends", |
| 106 | "type": "Bar" |
| 107 | }, |
| 108 | { |
| 109 | "name": "Item Wise Annual Expenditure", |
| 110 | "chart_name": "Item Wise Annual Expenditure", |
| 111 | "chart_type": "Report", |
| 112 | "custom_options": json.dumps({ |
| 113 | "axisOptions": {"shortenYAxisNumbers": 1}, |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 114 | "tooltipOptions": {} |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 115 | }), |
| 116 | "doctype": "Dashboard Chart", |
| 117 | "filters_json": json.dumps({ |
| 118 | "period": "Monthly", |
| 119 | "based_on": "Item", |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 120 | "fiscal_year": fiscal_year_name, |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 121 | "company": company.name, |
| 122 | "period_based_on": "posting_date" |
| 123 | }), |
| 124 | "is_custom": 1, |
| 125 | "is_public": 1, |
| 126 | "owner": "Administrator", |
| 127 | "report_name": "Purchase Receipt Trends", |
| 128 | "type": "Bar" |
| 129 | }, |
| 130 | { |
| 131 | "name": "Warehouse wise Stock Value", |
| 132 | "chart_name": "Warehouse wise Stock Value", |
| 133 | "chart_type": "Custom", |
| 134 | "doctype": "Dashboard Chart", |
| 135 | "filters_json": json.dumps({}), |
| 136 | "is_custom": 0, |
| 137 | "is_public": 1, |
| 138 | "owner": "Administrator", |
| 139 | "source": "Warehouse wise Stock Value", |
| 140 | "type": "Bar" |
| 141 | } |
| 142 | |
| 143 | ] |
| 144 | |
| 145 | def get_number_cards(): |
| 146 | return [ |
| 147 | { |
| 148 | "name": "Amount Payable against Receipt", |
| 149 | "label": "Amount Payable against Receipt", |
| 150 | "function": "Sum", |
| 151 | "aggregate_function_based_on": "base_grand_total", |
| 152 | "doctype": "Number Card", |
| 153 | "document_type": "Purchase Receipt", |
| 154 | "filters_json": json.dumps( |
| 155 | [["Purchase Receipt","status","=","To Bill",False], |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 156 | ["Purchase Receipt","company","=", company.name, False], |
| 157 | ["Purchase Receipt", "posting_date", "Between", [start_date,end_date], False]] |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 158 | ), |
| 159 | "is_public": 1, |
| 160 | "owner": "Administrator", |
| 161 | "show_percentage_stats": 1, |
| 162 | "stats_time_interval": "Daily" |
| 163 | }, |
| 164 | { |
| 165 | "name": "Amount Receivable against Delivery", |
| 166 | "label": "Amount Receivable against Delivery", |
| 167 | "function": "Sum", |
| 168 | "aggregate_function_based_on": "base_grand_total", |
| 169 | "doctype": "Number Card", |
| 170 | "document_type": "Delivery Note", |
| 171 | "filters_json": json.dumps( |
| 172 | [["Delivery Note","company","=",company.name,False], |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 173 | ["Delivery Note","status","=","To Bill",False], |
| 174 | ["Delivery Note", "posting_date", "Between", [start_date,end_date], False]] |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 175 | ), |
| 176 | "is_public": 1, |
| 177 | "owner": "Administrator", |
| 178 | "show_percentage_stats": 1, |
| 179 | "stats_time_interval": "Daily" |
| 180 | }, |
| 181 | { |
| 182 | "name": "Purchase Receipts to Bill", |
| 183 | "label": "Purchase Receipts to Bill", |
| 184 | "function": "Count", |
| 185 | "doctype": "Number Card", |
| 186 | "document_type": "Purchase Receipt", |
| 187 | "filters_json": json.dumps( |
| 188 | [["Purchase Receipt","status","=","To Bill",False], |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 189 | ["Purchase Receipt","company","=", company.name, False], |
| 190 | ["Purchase Receipt", "posting_date", "Between", [start_date,end_date], False]] |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 191 | ), |
| 192 | "is_public": 1, |
| 193 | "owner": "Administrator", |
| 194 | "show_percentage_stats": 1, |
| 195 | "stats_time_interval": "Daily" |
| 196 | }, |
| 197 | { |
| 198 | "name": "Delivery Notes to Bill", |
| 199 | "label": "Delivery Notes to Bill", |
| 200 | "function": "Count", |
| 201 | "doctype": "Number Card", |
| 202 | "document_type": "Delivery Note", |
| 203 | "filters_json": json.dumps( |
| 204 | [["Delivery Note","company","=",company.name,False], |
marination | a5fcaf6 | 2020-05-19 13:05:22 +0530 | [diff] [blame] | 205 | ["Delivery Note","status","=","To Bill",False], |
| 206 | ["Delivery Note", "posting_date", "Between", [start_date,end_date], False]] |
marination | be5c45a | 2020-05-15 13:21:58 +0530 | [diff] [blame] | 207 | ), |
| 208 | "is_public": 1, |
| 209 | "owner": "Administrator", |
| 210 | "show_percentage_stats": 1, |
| 211 | "stats_time_interval": "Daily" |
| 212 | } |
| 213 | ] |