chore: Export Buying Dashboard (#22767)
* chore: Export Buying Dashboard
* fix: Use Timespan instead of Between for static filters
diff --git a/erpnext/buying/buying_dashboard/buying/buying.json b/erpnext/buying/buying_dashboard/buying/buying.json
new file mode 100644
index 0000000..ab7ebac
--- /dev/null
+++ b/erpnext/buying/buying_dashboard/buying/buying.json
@@ -0,0 +1,46 @@
+{
+ "cards": [
+ {
+ "card": "Annual Purchase"
+ },
+ {
+ "card": "Purchase Orders to Receive"
+ },
+ {
+ "card": "Purchase Orders to Bill"
+ },
+ {
+ "card": "Active Suppliers"
+ }
+ ],
+ "charts": [
+ {
+ "chart": "Purchase Order Trends",
+ "width": "Full"
+ },
+ {
+ "chart": "Material Request Analysis",
+ "width": "Half"
+ },
+ {
+ "chart": "Purchase Order Analysis",
+ "width": "Half"
+ },
+ {
+ "chart": "Top Suppliers",
+ "width": "Full"
+ }
+ ],
+ "creation": "2020-07-20 21:01:02.541065",
+ "dashboard_name": "Buying",
+ "docstatus": 0,
+ "doctype": "Dashboard",
+ "idx": 0,
+ "is_default": 1,
+ "is_standard": 1,
+ "modified": "2020-07-22 12:48:38.112744",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Buying",
+ "owner": "Administrator"
+}
\ No newline at end of file
diff --git a/erpnext/buying/dashboard_chart/material_request_analysis/material_request_analysis.json b/erpnext/buying/dashboard_chart/material_request_analysis/material_request_analysis.json
new file mode 100644
index 0000000..0b66f1f
--- /dev/null
+++ b/erpnext/buying/dashboard_chart/material_request_analysis/material_request_analysis.json
@@ -0,0 +1,27 @@
+{
+ "chart_name": "Material Request Analysis",
+ "chart_type": "Group By",
+ "creation": "2020-07-20 21:01:02.242563",
+ "custom_options": "{\"height\": 300}",
+ "docstatus": 0,
+ "doctype": "Dashboard Chart",
+ "document_type": "Material Request",
+ "dynamic_filters_json": "[[\"Material Request\",\"company\",\"=\",\"frappe.defaults.get_user_default(\\\"Company\\\")\"]]",
+ "filters_json": "[[\"Material Request\",\"status\",\"not in\",[\"Draft\",\"Cancelled\",\"Stopped\",null],false],[\"Material Request\",\"material_request_type\",\"=\",\"Purchase\",false],[\"Material Request\",\"docstatus\",\"=\",\"1\",false],[\"Material Request\",\"transaction_date\",\"Timespan\",\"last quarter\",false]]",
+ "group_by_based_on": "status",
+ "group_by_type": "Count",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "last_synced_on": "2020-07-22 12:43:56.961250",
+ "modified": "2020-07-22 21:20:51.840194",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Material Request Analysis",
+ "number_of_groups": 0,
+ "owner": "Administrator",
+ "timeseries": 0,
+ "type": "Donut",
+ "use_report_chart": 0,
+ "y_axis": []
+}
\ No newline at end of file
diff --git a/erpnext/buying/dashboard_chart/purchase_order_analysis/purchase_order_analysis.json b/erpnext/buying/dashboard_chart/purchase_order_analysis/purchase_order_analysis.json
new file mode 100644
index 0000000..020755b
--- /dev/null
+++ b/erpnext/buying/dashboard_chart/purchase_order_analysis/purchase_order_analysis.json
@@ -0,0 +1,24 @@
+{
+ "chart_name": "Purchase Order Analysis",
+ "chart_type": "Report",
+ "creation": "2020-07-20 21:01:02.203880",
+ "custom_options": "{\"type\": \"donut\", \"height\": 300, \"axisOptions\": {\"shortenYAxisNumbers\": 1}}",
+ "docstatus": 0,
+ "doctype": "Dashboard Chart",
+ "dynamic_filters_json": "{\"company\":\"frappe.defaults.get_user_default(\\\"Company\\\")\",\"from_date\":\"frappe.datetime.add_months(frappe.datetime.nowdate(), -1)\",\"to_date\":\"frappe.datetime.nowdate()\"}",
+ "filters_json": "{\"group_by_po\":0}",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "modified": "2020-07-22 12:44:35.754973",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Purchase Order Analysis",
+ "number_of_groups": 0,
+ "owner": "Administrator",
+ "report_name": "Purchase Order Analysis",
+ "timeseries": 0,
+ "type": "Donut",
+ "use_report_chart": 1,
+ "y_axis": []
+}
\ No newline at end of file
diff --git a/erpnext/buying/dashboard_chart/purchase_order_trends/purchase_order_trends.json b/erpnext/buying/dashboard_chart/purchase_order_trends/purchase_order_trends.json
new file mode 100644
index 0000000..6452ed2
--- /dev/null
+++ b/erpnext/buying/dashboard_chart/purchase_order_trends/purchase_order_trends.json
@@ -0,0 +1,24 @@
+{
+ "chart_name": "Purchase Order Trends",
+ "chart_type": "Report",
+ "creation": "2020-07-20 21:01:02.295012",
+ "custom_options": "{\"type\": \"line\", \"axisOptions\": {\"shortenYAxisNumbers\": 1}, \"tooltipOptions\": {}, \"lineOptions\": {\"regionFill\": 1}}",
+ "docstatus": 0,
+ "doctype": "Dashboard Chart",
+ "dynamic_filters_json": "{\"company\":\"frappe.defaults.get_user_default(\\\"Company\\\")\",\"fiscal_year\":\"frappe.sys_defaults.fiscal_year\"}",
+ "filters_json": "{\"period\":\"Monthly\",\"period_based_on\":\"posting_date\",\"based_on\":\"Item\"}",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "modified": "2020-07-21 16:13:25.092287",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Purchase Order Trends",
+ "number_of_groups": 0,
+ "owner": "Administrator",
+ "report_name": "Purchase Order Trends",
+ "timeseries": 0,
+ "type": "Line",
+ "use_report_chart": 1,
+ "y_axis": []
+}
\ No newline at end of file
diff --git a/erpnext/buying/dashboard_chart/top_suppliers/top_suppliers.json b/erpnext/buying/dashboard_chart/top_suppliers/top_suppliers.json
new file mode 100644
index 0000000..6f7da8e
--- /dev/null
+++ b/erpnext/buying/dashboard_chart/top_suppliers/top_suppliers.json
@@ -0,0 +1,23 @@
+{
+ "chart_name": "Top Suppliers",
+ "chart_type": "Report",
+ "creation": "2020-07-20 21:01:02.329519",
+ "docstatus": 0,
+ "doctype": "Dashboard Chart",
+ "dynamic_filters_json": "{\"company\":\"frappe.defaults.get_user_default(\\\"Company\\\")\",\"fiscal_year\":\"frappe.sys_defaults.fiscal_year\"}",
+ "filters_json": "{\"period\":\"Monthly\",\"period_based_on\":\"posting_date\",\"based_on\":\"Supplier\"}",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "modified": "2020-07-22 12:43:40.829652",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Top Suppliers",
+ "number_of_groups": 0,
+ "owner": "Administrator",
+ "report_name": "Purchase Receipt Trends",
+ "timeseries": 0,
+ "type": "Bar",
+ "use_report_chart": 1,
+ "y_axis": []
+}
\ No newline at end of file
diff --git a/erpnext/buying/dashboard_fixtures.py b/erpnext/buying/dashboard_fixtures.py
deleted file mode 100644
index c6e2ffa..0000000
--- a/erpnext/buying/dashboard_fixtures.py
+++ /dev/null
@@ -1,211 +0,0 @@
-# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-import frappe
-import json
-from frappe import _
-from frappe.utils import nowdate
-from erpnext.accounts.dashboard_fixtures import _get_fiscal_year
-
-def get_data():
-
- fiscal_year = _get_fiscal_year(nowdate())
-
- if not fiscal_year:
- return frappe._dict()
-
- company = frappe.get_doc("Company", get_company_for_dashboards())
- fiscal_year_name = fiscal_year.get("name")
- start_date = str(fiscal_year.get("year_start_date"))
- end_date = str(fiscal_year.get("year_end_date"))
-
- return frappe._dict({
- "dashboards": get_dashboards(),
- "charts": get_charts(company, fiscal_year_name, start_date, end_date),
- "number_cards": get_number_cards(company, fiscal_year_name, start_date, end_date),
- })
-
-def get_company_for_dashboards():
- company = frappe.defaults.get_defaults().company
- if company:
- return company
- else:
- company_list = frappe.get_list("Company")
- if company_list:
- return company_list[0].name
- return None
-
-def get_dashboards():
- return [{
- "name": "Buying",
- "dashboard_name": "Buying",
- "charts": [
- { "chart": "Purchase Order Trends", "width": "Full"},
- { "chart": "Material Request Analysis", "width": "Half"},
- { "chart": "Purchase Order Analysis", "width": "Half"},
- { "chart": "Top Suppliers", "width": "Full"}
- ],
- "cards": [
- { "card": "Annual Purchase"},
- { "card": "Purchase Orders to Receive"},
- { "card": "Purchase Orders to Bill"},
- { "card": "Active Suppliers"}
- ]
- }]
-
-def get_charts(company, fiscal_year_name, start_date, end_date):
- return [
- {
- "name": "Purchase Order Analysis",
- "chart_name": _("Purchase Order Analysis"),
- "chart_type": "Report",
- "custom_options": json.dumps({
- "type": "donut",
- "height": 300,
- "axisOptions": {"shortenYAxisNumbers": 1}
- }),
- "doctype": "Dashboard Chart",
- "filters_json": json.dumps({
- "company": company.name,
- "from_date": start_date,
- "to_date": end_date
- }),
- "is_custom": 1,
- "is_public": 1,
- "owner": "Administrator",
- "report_name": "Purchase Order Analysis",
- "type": "Donut"
- },
- {
- "name": "Material Request Analysis",
- "chart_name": _("Material Request Analysis"),
- "chart_type": "Group By",
- "custom_options": json.dumps({"height": 300}),
- "doctype": "Dashboard Chart",
- "document_type": "Material Request",
- "filters_json": json.dumps(
- [["Material Request", "status", "not in", ["Draft", "Cancelled", "Stopped", None], False],
- ["Material Request", "material_request_type", "=", "Purchase", False],
- ["Material Request", "company", "=", company.name, False],
- ["Material Request", "docstatus", "=", 1, False],
- ["Material Request", "transaction_date", "Between", [start_date, end_date], False]]
- ),
- "group_by_based_on": "status",
- "group_by_type": "Count",
- "is_custom": 0,
- "is_public": 1,
- "number_of_groups": 0,
- "owner": "Administrator",
- "type": "Donut"
- },
- {
- "name": "Purchase Order Trends",
- "chart_name": _("Purchase Order Trends"),
- "chart_type": "Report",
- "custom_options": json.dumps({
- "type": "line",
- "axisOptions": {"shortenYAxisNumbers": 1},
- "tooltipOptions": {},
- "lineOptions": {
- "regionFill": 1
- }
- }),
- "doctype": "Dashboard Chart",
- "filters_json": json.dumps({
- "company": company.name,
- "period": "Monthly",
- "fiscal_year": fiscal_year_name,
- "period_based_on": "posting_date",
- "based_on": "Item"
- }),
- "is_custom": 1,
- "is_public": 1,
- "owner": "Administrator",
- "report_name": "Purchase Order Trends",
- "type": "Line"
- },
- {
- "name": "Top Suppliers",
- "chart_name": _("Top Suppliers"),
- "chart_type": "Report",
- "doctype": "Dashboard Chart",
- "filters_json": json.dumps({
- "company": company.name,
- "period": "Monthly",
- "fiscal_year": fiscal_year_name,
- "period_based_on": "posting_date",
- "based_on": "Supplier"
- }),
- "is_custom": 1,
- "is_public": 1,
- "owner": "Administrator",
- "report_name": "Purchase Receipt Trends",
- "type": "Bar"
- }
- ]
-
-def get_number_cards(company, fiscal_year_name, start_date, end_date):
- return [
- {
- "name": "Annual Purchase",
- "aggregate_function_based_on": "base_net_total",
- "doctype": "Number Card",
- "document_type": "Purchase Order",
- "filters_json": json.dumps([
- ["Purchase Order", "transaction_date", "Between", [start_date, end_date], False],
- ["Purchase Order", "status", "not in", ["Draft", "Cancelled", "Closed", None], False],
- ["Purchase Order", "docstatus", "=", 1, False],
- ["Purchase Order", "company", "=", company.name, False]
- ]),
- "function": "Sum",
- "is_public": 1,
- "label": _("Annual Purchase"),
- "owner": "Administrator",
- "show_percentage_stats": 1,
- "stats_time_interval": "Monthly"
- },
- {
- "name": "Purchase Orders to Receive",
- "doctype": "Number Card",
- "document_type": "Purchase Order",
- "filters_json": json.dumps([
- ["Purchase Order", "status", "in", ["To Receive and Bill", "To Receive", None], False],
- ["Purchase Order", "docstatus", "=", 1, False],
- ["Purchase Order", "company", "=", company.name, False]
- ]),
- "function": "Count",
- "is_public": 1,
- "label": _("Purchase Orders to Receive"),
- "owner": "Administrator",
- "show_percentage_stats": 1,
- "stats_time_interval": "Weekly"
- },
- {
- "name": "Purchase Orders to Bill",
- "doctype": "Number Card",
- "document_type": "Purchase Order",
- "filters_json": json.dumps([
- ["Purchase Order", "status", "in", ["To Receive and Bill", "To Bill", None], False],
- ["Purchase Order", "docstatus", "=", 1, False],
- ["Purchase Order", "company", "=", company.name, False]
- ]),
- "function": "Count",
- "is_public": 1,
- "label": _("Purchase Orders to Bill"),
- "owner": "Administrator",
- "show_percentage_stats": 1,
- "stats_time_interval": "Weekly"
- },
- {
- "name": "Active Suppliers",
- "doctype": "Number Card",
- "document_type": "Supplier",
- "filters_json": json.dumps([["Supplier", "disabled", "=", "0"]]),
- "function": "Count",
- "is_public": 1,
- "label": "Active Suppliers",
- "owner": "Administrator",
- "show_percentage_stats": 1,
- "stats_time_interval": "Monthly"
- }
- ]
\ No newline at end of file
diff --git a/erpnext/buying/number_card/active_suppliers/active_suppliers.json b/erpnext/buying/number_card/active_suppliers/active_suppliers.json
new file mode 100644
index 0000000..91d5b13
--- /dev/null
+++ b/erpnext/buying/number_card/active_suppliers/active_suppliers.json
@@ -0,0 +1,20 @@
+{
+ "creation": "2020-07-20 21:01:02.499689",
+ "docstatus": 0,
+ "doctype": "Number Card",
+ "document_type": "Supplier",
+ "filters_json": "[[\"Supplier\",\"disabled\",\"=\",\"0\"]]",
+ "function": "Count",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "label": "Active Suppliers",
+ "modified": "2020-07-22 12:48:23.295193",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Active Suppliers",
+ "owner": "Administrator",
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Monthly",
+ "type": "Document Type"
+}
\ No newline at end of file
diff --git a/erpnext/buying/number_card/annual_purchase/annual_purchase.json b/erpnext/buying/number_card/annual_purchase/annual_purchase.json
new file mode 100644
index 0000000..79f1b65
--- /dev/null
+++ b/erpnext/buying/number_card/annual_purchase/annual_purchase.json
@@ -0,0 +1,22 @@
+{
+ "aggregate_function_based_on": "base_net_total",
+ "creation": "2020-07-20 21:01:02.367127",
+ "docstatus": 0,
+ "doctype": "Number Card",
+ "document_type": "Purchase Order",
+ "dynamic_filters_json": "[[\"Purchase Order\",\"company\",\"=\",\"frappe.defaults.get_user_default(\\\"Company\\\")\"]]",
+ "filters_json": "[[\"Purchase Order\",\"transaction_date\",\"Timespan\",\"this year\",false],[\"Purchase Order\",\"status\",\"not in\",[\"Draft\",\"Cancelled\",\"Closed\",null],false],[\"Purchase Order\",\"docstatus\",\"=\",\"1\",false]]",
+ "function": "Sum",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "label": "Annual Purchase",
+ "modified": "2020-07-22 21:21:58.755188",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Annual Purchase",
+ "owner": "Administrator",
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Monthly",
+ "type": "Document Type"
+}
\ No newline at end of file
diff --git a/erpnext/buying/number_card/purchase_orders_to_bill/purchase_orders_to_bill.json b/erpnext/buying/number_card/purchase_orders_to_bill/purchase_orders_to_bill.json
new file mode 100644
index 0000000..44a0456
--- /dev/null
+++ b/erpnext/buying/number_card/purchase_orders_to_bill/purchase_orders_to_bill.json
@@ -0,0 +1,21 @@
+{
+ "creation": "2020-07-20 21:01:02.468514",
+ "docstatus": 0,
+ "doctype": "Number Card",
+ "document_type": "Purchase Order",
+ "dynamic_filters_json": "[[\"Purchase Order\",\"company\",\"=\",\"frappe.defaults.get_user_default(\\\"Company\\\")\"]]",
+ "filters_json": "[[\"Purchase Order\",\"status\",\"in\",[\"To Receive and Bill\",\"To Bill\",null],false],[\"Purchase Order\",\"docstatus\",\"=\",1,false]]",
+ "function": "Count",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "label": "Purchase Orders to Bill",
+ "modified": "2020-07-22 12:48:10.300711",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Purchase Orders to Bill",
+ "owner": "Administrator",
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Weekly",
+ "type": "Document Type"
+}
\ No newline at end of file
diff --git a/erpnext/buying/number_card/purchase_orders_to_receive/purchase_orders_to_receive.json b/erpnext/buying/number_card/purchase_orders_to_receive/purchase_orders_to_receive.json
new file mode 100644
index 0000000..442dab4
--- /dev/null
+++ b/erpnext/buying/number_card/purchase_orders_to_receive/purchase_orders_to_receive.json
@@ -0,0 +1,21 @@
+{
+ "creation": "2020-07-20 21:01:02.438012",
+ "docstatus": 0,
+ "doctype": "Number Card",
+ "document_type": "Purchase Order",
+ "dynamic_filters_json": "[[\"Purchase Order\",\"company\",\"=\",\"frappe.defaults.get_user_default(\\\"Company\\\")\"]]",
+ "filters_json": "[[\"Purchase Order\",\"status\",\"in\",[\"To Receive and Bill\",\"To Receive\",null],false],[\"Purchase Order\",\"docstatus\",\"=\",1,false]]",
+ "function": "Count",
+ "idx": 0,
+ "is_public": 1,
+ "is_standard": 1,
+ "label": "Purchase Orders to Receive",
+ "modified": "2020-07-22 12:47:47.460080",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Purchase Orders to Receive",
+ "owner": "Administrator",
+ "show_percentage_stats": 1,
+ "stats_time_interval": "Weekly",
+ "type": "Document Type"
+}
\ No newline at end of file