From 0d19c18c0628fc7f4a2727c8e5c9d0fe0f93d66d Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Sat, 24 May 2025 12:55:05 +0530 Subject: [PATCH 1/2] fix: patch to rename group_by filter in custom reports --- erpnext/patches.txt | 1 + ...p_by_to_categorize_by_in_custom_reports.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c02ce0d6785..b9741620d73 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -413,3 +413,4 @@ erpnext.patches.v14_0.set_update_price_list_based_on erpnext.patches.v15_0.update_journal_entry_type erpnext.patches.v15_0.set_grand_total_to_default_mop execute:frappe.db.set_single_value("Accounts Settings", "use_new_budget_controller", True) +erpnext.patches.v15_0.rename_group_by_to_categorize_by_in_custom_reports diff --git a/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py b/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py new file mode 100644 index 00000000000..f37d3cad18d --- /dev/null +++ b/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py @@ -0,0 +1,21 @@ +import frappe + + +def execute(): + frappe.db.sql( + """ + UPDATE `tabReport` + SET `json` = JSON_SET( + JSON_REMOVE(json, '$.filters.group_by'), + '$.filters.categorize_by', + REPLACE(JSON_UNQUOTE(JSON_EXTRACT(json, '$.filters.group_by')), 'Group', 'Categorize') + ) + WHERE + JSON_CONTAINS_PATH(json, 'one', '$.filters.group_by') + AND `reference_report` = CASE + WHEN `reference_report` = 'Supplier Quotation Comparison' THEN 'Supplier Quotation Comparison' + ELSE 'General Ledger' + END + AND `report_type` = 'Custom Report' + """ + ) From 48eccb1f734a1e0e158e28892759bc77c6e4904e Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Sat, 24 May 2025 14:53:04 +0530 Subject: [PATCH 2/2] fix: using python instead of sql query --- ...p_by_to_categorize_by_in_custom_reports.py | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py b/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py index f37d3cad18d..bc671a4a6ac 100644 --- a/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py +++ b/erpnext/patches/v15_0/rename_group_by_to_categorize_by_in_custom_reports.py @@ -1,21 +1,24 @@ +import json + import frappe def execute(): - frappe.db.sql( - """ - UPDATE `tabReport` - SET `json` = JSON_SET( - JSON_REMOVE(json, '$.filters.group_by'), - '$.filters.categorize_by', - REPLACE(JSON_UNQUOTE(JSON_EXTRACT(json, '$.filters.group_by')), 'Group', 'Categorize') - ) - WHERE - JSON_CONTAINS_PATH(json, 'one', '$.filters.group_by') - AND `reference_report` = CASE - WHEN `reference_report` = 'Supplier Quotation Comparison' THEN 'Supplier Quotation Comparison' - ELSE 'General Ledger' - END - AND `report_type` = 'Custom Report' - """ + custom_reports = frappe.get_all( + "Report", + filters={ + "report_type": "Custom Report", + "reference_report": ["in", ["General Ledger", "Supplier Quotation Comparison"]], + }, + fields=["name", "json"], ) + + for report in custom_reports: + report_json = json.loads(report.json) + + if "filters" in report_json and "group_by" in report_json["filters"]: + report_json["filters"]["categorize_by"] = ( + report_json["filters"].pop("group_by").replace("Group", "Categorize") + ) + + frappe.db.set_value("Report", report.name, "json", json.dumps(report_json))