From c16e93e0f42e2a7f753198e26f798303a31934b9 Mon Sep 17 00:00:00 2001 From: Nihantra Patel Date: Mon, 20 May 2024 15:51:27 +0530 Subject: [PATCH] fix: add include closed orders option in so/po trends report --- .../purchase_order_trends/purchase_order_trends.js | 7 +++++++ erpnext/controllers/trends.py | 10 ++++------ .../report/sales_order_trends/sales_order_trends.js | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js b/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js index 56684a8659..9b193a34d8 100644 --- a/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js +++ b/erpnext/buying/report/purchase_order_trends/purchase_order_trends.js @@ -2,3 +2,10 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Purchase Order Trends"] = $.extend({}, erpnext.purchase_trends_filters); + +frappe.query_reports["Purchase Order Trends"]["filters"].push({ + fieldname: "include_closed_orders", + label: __("Include Closed Orders"), + fieldtype: "Check", + default: 0, +}); diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py index 5c1fdeb226..a80e52e505 100644 --- a/erpnext/controllers/trends.py +++ b/erpnext/controllers/trends.py @@ -57,7 +57,6 @@ def validate_filters(filters): def get_data(filters, conditions): - data = [] inc, cond = "", "" query_details = conditions["based_on_select"] + conditions["period_wise_select"] @@ -76,8 +75,9 @@ def get_data(filters, conditions): if conditions["based_on_select"] in ["t1.project,", "t2.project,"]: cond = " and " + conditions["based_on_select"][:-1] + " IS Not NULL" - if conditions.get("trans") in ["Sales Order", "Purchase Order"]: - cond += " and t1.status != 'Closed'" + if not filters.get("include_closed_orders"): + if conditions.get("trans") in ["Sales Order", "Purchase Order"]: + cond += " and t1.status != 'Closed'" if conditions.get("trans") == "Quotation" and filters.get("group_by") == "Customer": cond += " and t1.quotation_to = 'Customer'" @@ -333,9 +333,7 @@ def based_wise_columns_query(based_on, trans): "Territory:Link/Territory:120", ] based_on_details["based_on_select"] = "t1.customer_name, t1.territory, " - based_on_details["based_on_group_by"] = ( - "t1.party_name" if trans == "Quotation" else "t1.customer" - ) + based_on_details["based_on_group_by"] = "t1.party_name" if trans == "Quotation" else "t1.customer" based_on_details["addl_tables"] = "" elif based_on == "Customer Group": diff --git a/erpnext/selling/report/sales_order_trends/sales_order_trends.js b/erpnext/selling/report/sales_order_trends/sales_order_trends.js index 28bd550493..a44353cf54 100644 --- a/erpnext/selling/report/sales_order_trends/sales_order_trends.js +++ b/erpnext/selling/report/sales_order_trends/sales_order_trends.js @@ -2,3 +2,10 @@ // License: GNU General Public License v3. See license.txt frappe.query_reports["Sales Order Trends"] = $.extend({}, erpnext.sales_trends_filters); + +frappe.query_reports["Sales Order Trends"]["filters"].push({ + fieldname: "include_closed_orders", + label: __("Include Closed Orders"), + fieldtype: "Check", + default: 0, +}); -- GitLab