diff --git a/frappe/core/doctype/prepared_report/prepared_report.py b/frappe/core/doctype/prepared_report/prepared_report.py index e947cee8ed..c27853f460 100644 --- a/frappe/core/doctype/prepared_report/prepared_report.py +++ b/frappe/core/doctype/prepared_report/prepared_report.py @@ -37,7 +37,10 @@ def run_background(prepared_report): custom_report_doc = report reference_report = custom_report_doc.reference_report report = frappe.get_doc("Report", reference_report) - report.custom_columns = custom_report_doc.json + if custom_report_doc.json: + data = json.loads(custom_report_doc.json) + if data: + report.custom_columns = data["columns"] result = generate_report_result( report=report, diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index 22d47d1120..9589507ca6 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -36,7 +36,10 @@ def get_report_doc(report_name): reference_report = custom_report_doc.reference_report doc = frappe.get_doc("Report", reference_report) doc.custom_report = report_name - doc.custom_columns = custom_report_doc.json + if custom_report_doc.json: + data = json.loads(custom_report_doc.json) + if data: + doc.custom_columns = data["columns"] doc.is_custom_report = True if not doc.is_permitted(): @@ -83,7 +86,7 @@ def generate_report_result(report, filters=None, user=None, custom_columns=None) if report.custom_columns: # saved columns (with custom columns / with different column order) - columns = json.loads(report.custom_columns) + columns = report.custom_columns # unsaved custom_columns if custom_columns: @@ -524,9 +527,12 @@ def save_report(reference_report, report_name, columns): "report_type": "Custom Report", }, ) + if docname: report = frappe.get_doc("Report", docname) - report.update({"json": columns}) + existing_jd = json.loads(report.json) + existing_jd["columns"] = json.loads(columns) + report.update({"json": json.dumps(existing_jd, separators=(',', ':'))}) report.save() frappe.msgprint(_("Report updated successfully")) @@ -536,7 +542,7 @@ def save_report(reference_report, report_name, columns): { "doctype": "Report", "report_name": report_name, - "json": columns, + "json": f'{{"columns":{columns}}}', "ref_doctype": report_doc.ref_doctype, "is_standard": "No", "report_type": "Custom Report", diff --git a/frappe/patches.txt b/frappe/patches.txt index 5251b3da30..516ddb6094 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -334,3 +334,4 @@ frappe.patches.v13_0.delete_package_publish_tool frappe.patches.v13_0.rename_list_view_setting_to_list_view_settings frappe.patches.v13_0.remove_twilio_settings frappe.patches.v12_0.rename_uploaded_files_with_proper_name +frappe.patches.v13_0.queryreport_columns diff --git a/frappe/patches/v13_0/queryreport_columns.py b/frappe/patches/v13_0/queryreport_columns.py new file mode 100644 index 0000000000..6c2a1b1219 --- /dev/null +++ b/frappe/patches/v13_0/queryreport_columns.py @@ -0,0 +1,22 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe +import json + +def execute(): + """Convert Query Report json to support other content""" + records = frappe.get_all('Report', + filters={ + "json": ["!=", ""] + }, + fields=["name", "json"] + ) + for record in records: + jstr = record["json"] + data = json.loads(jstr) + if isinstance(data, list): + # double escape braces + jstr = f'{{"columns":{jstr}}}' + frappe.db.update('Report', record["name"], "json", jstr)