blob: 0f1fd128f0b3df0f0661d6b9eae3eb9ae1e5c6e9 [file] [log] [blame]
marinationbe5c45a2020-05-15 13:21:58 +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
Nabin Hait8b686a52020-05-19 19:08:30 +05306from frappe import _
marinationbe5c45a2020-05-15 13:21:58 +05307from frappe.utils import nowdate
8from erpnext.accounts.utils import get_fiscal_year
9
10def get_data():
11 return frappe._dict({
12 "dashboards": get_dashboards(),
13 "charts": get_charts(),
14 "number_cards": get_number_cards(),
15 })
16
17def get_company_for_dashboards():
18 company = frappe.defaults.get_defaults().company
19 if company:
20 return company
21 else:
22 company_list = frappe.get_list("Company")
23 if company_list:
24 return company_list[0].name
25 return None
26
27company = frappe.get_doc("Company", get_company_for_dashboards())
marinationa5fcaf62020-05-19 13:05:22 +053028fiscal_year = get_fiscal_year(nowdate(), as_dict=1)
29fiscal_year_name = fiscal_year.get("name")
30start_date = str(fiscal_year.get("year_start_date"))
31end_date = str(fiscal_year.get("year_end_date"))
marinationbe5c45a2020-05-15 13:21:58 +053032
33def get_dashboards():
34 return [{
35 "name": "Stock",
36 "dashboard_name": "Stock",
37 "charts": [
Nabin Hait8b686a52020-05-19 19:08:30 +053038 { "chart": "Warehouse wise Stock Value", "width": "Full"},
39 { "chart": "Purchase Receipt Trends", "width": "Half"},
40 { "chart": "Delivery Trends", "width": "Half"},
41 { "chart": "Oldest Items", "width": "Half"},
42 { "chart": "Item Shortage Summary", "width": "Half"}
marinationbe5c45a2020-05-15 13:21:58 +053043 ],
44 "cards": [
Nabin Hait8b686a52020-05-19 19:08:30 +053045 { "card": "Total Active Items"},
46 { "card": "Total Warehouses"},
47 { "card": "Total Stock Value"}
marinationbe5c45a2020-05-15 13:21:58 +053048 ]
49 }]
50
51def get_charts():
52 return [
53 {
marinationbe5c45a2020-05-15 13:21:58 +053054 "doctype": "Dashboard Chart",
Nabin Hait8b686a52020-05-19 19:08:30 +053055 "name": "Purchase Receipt Trends",
56 "time_interval": "Monthly",
57 "chart_name": _("Purchase Receipt Trends"),
58 "timespan": "Last Year",
59 "color": "#7b933d",
60 "value_based_on": "base_net_total",
61 "filters_json": json.dumps([["Purchase Receipt", "docstatus", "=", 1]]),
62 "chart_type": "Sum",
63 "timeseries": 1,
64 "based_on": "posting_date",
65 "owner": "Administrator",
66 "document_type": "Purchase Receipt",
67 "type": "Bar",
68 "width": "Half",
69 "is_public": 1
70 },
71 {
72 "doctype": "Dashboard Chart",
73 "name": "Delivery Trends",
74 "time_interval": "Monthly",
75 "chart_name": _("Delivery Trends"),
76 "timespan": "Last Year",
77 "color": "#7b933d",
78 "value_based_on": "base_net_total",
79 "filters_json": json.dumps([["Delivery Note", "docstatus", "=", 1]]),
80 "chart_type": "Sum",
81 "timeseries": 1,
82 "based_on": "posting_date",
83 "owner": "Administrator",
84 "document_type": "Delivery Note",
85 "type": "Bar",
86 "width": "Half",
87 "is_public": 1
88 },
89 {
90 "name": "Warehouse wise Stock Value",
91 "chart_name": _("Warehouse wise Stock Value"),
92 "chart_type": "Custom",
93 "doctype": "Dashboard Chart",
94 "filters_json": json.dumps({}),
95 "is_custom": 0,
marinationbe5c45a2020-05-15 13:21:58 +053096 "is_public": 1,
97 "owner": "Administrator",
Nabin Hait8b686a52020-05-19 19:08:30 +053098 "source": "Warehouse wise Stock Value",
marinationbe5c45a2020-05-15 13:21:58 +053099 "type": "Bar"
100 },
101 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530102 "name": "Oldest Items",
103 "chart_name": _("Oldest Items"),
marinationbe5c45a2020-05-15 13:21:58 +0530104 "chart_type": "Report",
105 "custom_options": json.dumps({
106 "colors": ["#5e64ff"]
107 }),
108 "doctype": "Dashboard Chart",
109 "filters_json": json.dumps({
110 "company": company.name,
111 "to_date": nowdate(),
112 "show_warehouse_wise_stock": 0
113 }),
114 "is_custom": 1,
115 "is_public": 1,
116 "owner": "Administrator",
117 "report_name": "Stock Ageing",
118 "type": "Bar"
119 },
120 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530121 "name": "Item Shortage Summary",
122 "chart_name": _("Item Shortage Summary"),
marinationbe5c45a2020-05-15 13:21:58 +0530123 "chart_type": "Report",
marinationbe5c45a2020-05-15 13:21:58 +0530124 "doctype": "Dashboard Chart",
125 "filters_json": json.dumps({
marinationbe5c45a2020-05-15 13:21:58 +0530126 "company": company.name
127 }),
128 "is_custom": 1,
129 "is_public": 1,
130 "owner": "Administrator",
Nabin Hait8b686a52020-05-19 19:08:30 +0530131 "report_name": "Item Shortage Report",
marinationbe5c45a2020-05-15 13:21:58 +0530132 "type": "Bar"
133 }
marinationbe5c45a2020-05-15 13:21:58 +0530134 ]
135
136def get_number_cards():
137 return [
138 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530139 "name": "Total Active Items",
140 "label": _("Total Active Items"),
marinationbe5c45a2020-05-15 13:21:58 +0530141 "function": "Count",
142 "doctype": "Number Card",
Nabin Hait8b686a52020-05-19 19:08:30 +0530143 "document_type": "Item",
144 "filters_json": json.dumps([["Item", "disabled", "=", 0]]),
marinationbe5c45a2020-05-15 13:21:58 +0530145 "is_public": 1,
146 "owner": "Administrator",
147 "show_percentage_stats": 1,
Nabin Hait8b686a52020-05-19 19:08:30 +0530148 "stats_time_interval": "Monthly"
marinationbe5c45a2020-05-15 13:21:58 +0530149 },
150 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530151 "name": "Total Warehouses",
152 "label": _("Total Warehouses"),
marinationbe5c45a2020-05-15 13:21:58 +0530153 "function": "Count",
154 "doctype": "Number Card",
Nabin Hait8b686a52020-05-19 19:08:30 +0530155 "document_type": "Warehouse",
156 "filters_json": json.dumps([["Warehouse", "disabled", "=", 0]]),
157 "is_public": 1,
158 "owner": "Administrator",
159 "show_percentage_stats": 1,
160 "stats_time_interval": "Monthly"
161 },
162 {
163 "name": "Total Stock Value",
164 "label": _("Total Stock Value"),
165 "function": "Sum",
166 "aggregate_function_based_on": "stock_value",
167 "doctype": "Number Card",
168 "document_type": "Bin",
169 "filters_json": json.dumps([]),
marinationbe5c45a2020-05-15 13:21:58 +0530170 "is_public": 1,
171 "owner": "Administrator",
172 "show_percentage_stats": 1,
173 "stats_time_interval": "Daily"
174 }
175 ]