blob: a106f70dd06c222f7bcf6af3a5065cf794807772 [file] [log] [blame]
Shivam Mishra28436d22020-05-06 15:19:10 +05301# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4import frappe
5import json
6
7
8def get_data():
9 return frappe._dict({
10 "dashboards": get_dashboards(),
11 "charts": get_charts(),
12 })
13
14def get_dashboards():
15 return [{
16 "name": "Accounts",
17 "dashboard_name": "Accounts",
18 "charts": [
19 { "chart": "Outgoing Bills (Sales Invoice)" },
20 { "chart": "Incoming Bills (Purchase Invoice)" },
21 { "chart": "Bank Balance" },
22 { "chart": "Income" },
23 { "chart": "Expenses" }
24 ]
25 }]
26
27def get_charts():
28 company = frappe.get_doc("Company", get_company_for_dashboards())
29 income_account = company.default_income_account or get_account("Income Account", company.name)
30 expense_account = company.default_expense_account or get_account("Expense Account", company.name)
31 bank_account = company.default_bank_account or get_account("Bank", company.name)
32
33 return [
34 {
35 "doctype": "Dashboard Chart",
36 "time_interval": "Quarterly",
37 "name": "Income",
38 "chart_name": "Income",
39 "timespan": "Last Year",
40 "color": None,
41 "filters_json": json.dumps({"company": company.name, "account": income_account}),
42 "source": "Account Balance Timeline",
43 "chart_type": "Custom",
44 "timeseries": 1,
45 "owner": "Administrator",
46 "type": "Line"
47 },
48 {
49 "doctype": "Dashboard Chart",
50 "time_interval": "Quarterly",
51 "name": "Expenses",
52 "chart_name": "Expenses",
53 "timespan": "Last Year",
54 "color": None,
55 "filters_json": json.dumps({"company": company.name, "account": expense_account}),
56 "source": "Account Balance Timeline",
57 "chart_type": "Custom",
58 "timeseries": 1,
59 "owner": "Administrator",
60 "type": "Line"
61 },
62 {
63 "doctype": "Dashboard Chart",
64 "time_interval": "Quarterly",
65 "name": "Bank Balance",
66 "chart_name": "Bank Balance",
67 "timespan": "Last Year",
68 "color": "#ffb868",
69 "filters_json": json.dumps({"company": company.name, "account": bank_account}),
70 "source": "Account Balance Timeline",
71 "chart_type": "Custom",
72 "timeseries": 1,
73 "owner": "Administrator",
74 "type": "Line"
75 },
76 {
77 "doctype": "Dashboard Chart",
78 "time_interval": "Monthly",
79 "name": "Incoming Bills (Purchase Invoice)",
80 "chart_name": "Incoming Bills (Purchase Invoice)",
81 "timespan": "Last Year",
82 "color": "#a83333",
83 "value_based_on": "base_grand_total",
84 "filters_json": json.dumps({}),
85 "chart_type": "Sum",
86 "timeseries": 1,
87 "based_on": "posting_date",
88 "owner": "Administrator",
89 "document_type": "Purchase Invoice",
90 "type": "Bar"
91 },
92 {
93 "doctype": "Dashboard Chart",
94 "time_interval": "Monthly",
95 "name": "Outgoing Bills (Sales Invoice)",
96 "chart_name": "Outgoing Bills (Sales Invoice)",
97 "timespan": "Last Year",
98 "color": "#7b933d",
99 "value_based_on": "base_grand_total",
100 "filters_json": json.dumps({}),
101 "chart_type": "Sum",
102 "timeseries": 1,
103 "based_on": "posting_date",
104 "owner": "Administrator",
105 "document_type": "Sales Invoice",
106 "type": "Bar"
107 }
108 ]
109
Suraj Shetty65d3ac82020-05-09 17:39:59 +0530110def get_account(account_type, company):
111 accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
112 if accounts:
113 return accounts[0].name
Shivam Mishra28436d22020-05-06 15:19:10 +0530114
115def get_company_for_dashboards():
116 company = frappe.defaults.get_defaults().company
117 if company:
118 return company
119 else:
120 company_list = frappe.get_list("Company")
121 if company_list:
122 return company_list[0].name
123 return None