blob: 7625b1ad283486efdd5d7645f8045c8dc3a29704 [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
Deepesh Garg9df45322020-06-11 21:33:43 +05308from erpnext.accounts.dashboard_fixtures import _get_fiscal_year
9from erpnext.buying.dashboard_fixtures import get_company_for_dashboards
marinationbe5c45a2020-05-15 13:21:58 +053010
11def get_data():
Deepesh Garg9df45322020-06-11 21:33:43 +053012 fiscal_year = _get_fiscal_year(nowdate())
13
14 if not fiscal_year:
15 return frappe._dict()
16
17 company = frappe.get_doc("Company", get_company_for_dashboards())
18 fiscal_year_name = fiscal_year.get("name")
19 start_date = str(fiscal_year.get("year_start_date"))
20 end_date = str(fiscal_year.get("year_end_date"))
21
marinationbe5c45a2020-05-15 13:21:58 +053022 return frappe._dict({
23 "dashboards": get_dashboards(),
Deepesh Garg9df45322020-06-11 21:33:43 +053024 "charts": get_charts(company, fiscal_year_name, start_date, end_date),
25 "number_cards": get_number_cards(company, fiscal_year_name, start_date, end_date),
marinationbe5c45a2020-05-15 13:21:58 +053026 })
27
marinationbe5c45a2020-05-15 13:21:58 +053028def get_dashboards():
29 return [{
30 "name": "Stock",
31 "dashboard_name": "Stock",
32 "charts": [
Nabin Hait8b686a52020-05-19 19:08:30 +053033 { "chart": "Warehouse wise Stock Value", "width": "Full"},
34 { "chart": "Purchase Receipt Trends", "width": "Half"},
35 { "chart": "Delivery Trends", "width": "Half"},
36 { "chart": "Oldest Items", "width": "Half"},
37 { "chart": "Item Shortage Summary", "width": "Half"}
marinationbe5c45a2020-05-15 13:21:58 +053038 ],
39 "cards": [
Nabin Hait8b686a52020-05-19 19:08:30 +053040 { "card": "Total Active Items"},
41 { "card": "Total Warehouses"},
42 { "card": "Total Stock Value"}
marinationbe5c45a2020-05-15 13:21:58 +053043 ]
44 }]
45
Deepesh Garg9df45322020-06-11 21:33:43 +053046def get_charts(company, fiscal_year_name, start_date, end_date):
marinationbe5c45a2020-05-15 13:21:58 +053047 return [
48 {
marinationbe5c45a2020-05-15 13:21:58 +053049 "doctype": "Dashboard Chart",
Nabin Hait8b686a52020-05-19 19:08:30 +053050 "name": "Purchase Receipt Trends",
51 "time_interval": "Monthly",
52 "chart_name": _("Purchase Receipt Trends"),
53 "timespan": "Last Year",
54 "color": "#7b933d",
55 "value_based_on": "base_net_total",
56 "filters_json": json.dumps([["Purchase Receipt", "docstatus", "=", 1]]),
57 "chart_type": "Sum",
58 "timeseries": 1,
59 "based_on": "posting_date",
60 "owner": "Administrator",
61 "document_type": "Purchase Receipt",
62 "type": "Bar",
63 "width": "Half",
64 "is_public": 1
65 },
66 {
67 "doctype": "Dashboard Chart",
68 "name": "Delivery Trends",
69 "time_interval": "Monthly",
70 "chart_name": _("Delivery Trends"),
71 "timespan": "Last Year",
72 "color": "#7b933d",
73 "value_based_on": "base_net_total",
74 "filters_json": json.dumps([["Delivery Note", "docstatus", "=", 1]]),
75 "chart_type": "Sum",
76 "timeseries": 1,
77 "based_on": "posting_date",
78 "owner": "Administrator",
79 "document_type": "Delivery Note",
80 "type": "Bar",
81 "width": "Half",
82 "is_public": 1
83 },
84 {
85 "name": "Warehouse wise Stock Value",
86 "chart_name": _("Warehouse wise Stock Value"),
87 "chart_type": "Custom",
88 "doctype": "Dashboard Chart",
89 "filters_json": json.dumps({}),
90 "is_custom": 0,
marinationbe5c45a2020-05-15 13:21:58 +053091 "is_public": 1,
92 "owner": "Administrator",
Nabin Hait8b686a52020-05-19 19:08:30 +053093 "source": "Warehouse wise Stock Value",
marinationbe5c45a2020-05-15 13:21:58 +053094 "type": "Bar"
95 },
96 {
Nabin Hait8b686a52020-05-19 19:08:30 +053097 "name": "Oldest Items",
98 "chart_name": _("Oldest Items"),
marinationbe5c45a2020-05-15 13:21:58 +053099 "chart_type": "Report",
100 "custom_options": json.dumps({
101 "colors": ["#5e64ff"]
102 }),
103 "doctype": "Dashboard Chart",
104 "filters_json": json.dumps({
105 "company": company.name,
106 "to_date": nowdate(),
107 "show_warehouse_wise_stock": 0
108 }),
109 "is_custom": 1,
110 "is_public": 1,
111 "owner": "Administrator",
112 "report_name": "Stock Ageing",
113 "type": "Bar"
114 },
115 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530116 "name": "Item Shortage Summary",
117 "chart_name": _("Item Shortage Summary"),
marinationbe5c45a2020-05-15 13:21:58 +0530118 "chart_type": "Report",
marinationbe5c45a2020-05-15 13:21:58 +0530119 "doctype": "Dashboard Chart",
120 "filters_json": json.dumps({
marinationbe5c45a2020-05-15 13:21:58 +0530121 "company": company.name
122 }),
123 "is_custom": 1,
124 "is_public": 1,
125 "owner": "Administrator",
Nabin Hait8b686a52020-05-19 19:08:30 +0530126 "report_name": "Item Shortage Report",
marinationbe5c45a2020-05-15 13:21:58 +0530127 "type": "Bar"
128 }
marinationbe5c45a2020-05-15 13:21:58 +0530129 ]
130
Deepesh Garg9df45322020-06-11 21:33:43 +0530131def get_number_cards(company, fiscal_year_name, start_date, end_date):
marinationbe5c45a2020-05-15 13:21:58 +0530132 return [
133 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530134 "name": "Total Active Items",
135 "label": _("Total Active Items"),
marinationbe5c45a2020-05-15 13:21:58 +0530136 "function": "Count",
137 "doctype": "Number Card",
Nabin Hait8b686a52020-05-19 19:08:30 +0530138 "document_type": "Item",
139 "filters_json": json.dumps([["Item", "disabled", "=", 0]]),
marinationbe5c45a2020-05-15 13:21:58 +0530140 "is_public": 1,
141 "owner": "Administrator",
142 "show_percentage_stats": 1,
Nabin Hait8b686a52020-05-19 19:08:30 +0530143 "stats_time_interval": "Monthly"
marinationbe5c45a2020-05-15 13:21:58 +0530144 },
145 {
Nabin Hait8b686a52020-05-19 19:08:30 +0530146 "name": "Total Warehouses",
147 "label": _("Total Warehouses"),
marinationbe5c45a2020-05-15 13:21:58 +0530148 "function": "Count",
149 "doctype": "Number Card",
Nabin Hait8b686a52020-05-19 19:08:30 +0530150 "document_type": "Warehouse",
151 "filters_json": json.dumps([["Warehouse", "disabled", "=", 0]]),
152 "is_public": 1,
153 "owner": "Administrator",
154 "show_percentage_stats": 1,
155 "stats_time_interval": "Monthly"
156 },
157 {
158 "name": "Total Stock Value",
159 "label": _("Total Stock Value"),
160 "function": "Sum",
161 "aggregate_function_based_on": "stock_value",
162 "doctype": "Number Card",
163 "document_type": "Bin",
164 "filters_json": json.dumps([]),
marinationbe5c45a2020-05-15 13:21:58 +0530165 "is_public": 1,
166 "owner": "Administrator",
167 "show_percentage_stats": 1,
168 "stats_time_interval": "Daily"
169 }
170 ]