Skip to content

Commit

Permalink
fix: better filename for prepared report
Browse files Browse the repository at this point in the history
avoid colons, windows doesn't like it

(cherry picked from commit 2c359f9)
  • Loading branch information
ankush authored and mergify[bot] committed Mar 13, 2024
1 parent ecf313e commit 8eb1b24
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frappe/core/doctype/prepared_report/prepared_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_prepared_data(self, with_file_name=False):
def generate_report(prepared_report):
update_job_id(prepared_report)

instance = frappe.get_doc("Prepared Report", prepared_report)
instance: PreparedReport = frappe.get_doc("Prepared Report", prepared_report)
report = frappe.get_doc("Report", instance.report_name)

add_data_to_monitor(report=instance.report_name)
Expand All @@ -109,7 +109,7 @@ def generate_report(prepared_report):
report.custom_columns = data["columns"]

result = generate_report_result(report=report, filters=instance.filters, user=instance.owner)
create_json_gz_file(result, instance.doctype, instance.name)
create_json_gz_file(result, instance.doctype, instance.name, instance.report_name)

instance.status = "Completed"
except Exception:
Expand Down Expand Up @@ -215,10 +215,12 @@ def delete_prepared_reports(reports):
prepared_report.delete(ignore_permissions=True, delete_permanently=True)


def create_json_gz_file(data, dt, dn):
def create_json_gz_file(data, dt, dn, report_name):
# Storing data in CSV file causes information loss
# Reports like P&L Statement were completely unsuable because of this
json_filename = "{}.json.gz".format(frappe.utils.data.format_datetime(frappe.utils.now(), "Y-m-d-H:M"))
json_filename = "{}_{}.json.gz".format(
frappe.scrub(report_name), frappe.utils.data.format_datetime(frappe.utils.now(), "Y-m-d-H-M")
)
encoded_content = frappe.safe_encode(frappe.as_json(data, indent=None, separators=(",", ":")))
compressed_content = gzip.compress(encoded_content)

Expand Down

0 comments on commit 8eb1b24

Please sign in to comment.