Merge pull request #25395 from ankush/large_report_entries
fix: allow exporting large reports that can't be rendered
This commit is contained in:
commit
8937a94c07
5 changed files with 38 additions and 22 deletions
|
|
@ -91,7 +91,7 @@ class PreparedReport(Document):
|
|||
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)
|
||||
|
|
@ -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:
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ def build_xlsx_data(data, visible_idx, include_indentation, include_filters=Fals
|
|||
datetime.timedelta,
|
||||
)
|
||||
|
||||
if len(visible_idx) == len(data.result):
|
||||
if len(visible_idx) == len(data.result) or not visible_idx:
|
||||
# It's not possible to have same length and different content.
|
||||
ignore_visible_idx = True
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -761,15 +761,19 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
|
||||
add_prepared_report_buttons(doc) {
|
||||
if (doc) {
|
||||
this.page.add_inner_button(__("Download Report"), function () {
|
||||
window.open(
|
||||
frappe.urllib.get_full_url(
|
||||
"/api/method/frappe.core.doctype.prepared_report.prepared_report.download_attachment?" +
|
||||
"dn=" +
|
||||
encodeURIComponent(doc.name)
|
||||
)
|
||||
);
|
||||
});
|
||||
this.page.add_inner_button(
|
||||
__("Download Report"),
|
||||
function () {
|
||||
window.open(
|
||||
frappe.urllib.get_full_url(
|
||||
"/api/method/frappe.core.doctype.prepared_report.prepared_report.download_attachment?" +
|
||||
"dn=" +
|
||||
encodeURIComponent(doc.name)
|
||||
)
|
||||
);
|
||||
},
|
||||
__("Actions")
|
||||
);
|
||||
|
||||
let pretty_diff = frappe.datetime.comment_when(doc.report_end_time);
|
||||
const days_old = frappe.datetime.get_day_diff(
|
||||
|
|
@ -953,6 +957,16 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
let data = this.data;
|
||||
let columns = this.columns.filter((col) => !col.hidden);
|
||||
|
||||
if (data.length > 100000) {
|
||||
let msg = __(
|
||||
"This report contains {0} rows and is too big to display in browser, you can {1} this report instead.",
|
||||
[cstr(format_number(data.length, null, 0)).bold(), __("export").bold()]
|
||||
);
|
||||
|
||||
this.toggle_message(true, `${frappe.utils.icon("solid-warning")} ${msg}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.raw_data.add_total_row && !this.report_settings.tree) {
|
||||
data = data.slice();
|
||||
data.splice(-1, 1);
|
||||
|
|
@ -1523,15 +1537,15 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
])
|
||||
);
|
||||
|
||||
const visible_idx = this.datatable.bodyRenderer.visibleRowIndices;
|
||||
if (visible_idx.length + 1 === this.data.length) {
|
||||
const visible_idx = this.datatable?.bodyRenderer.visibleRowIndices || [];
|
||||
if (visible_idx.length + 1 === this.data?.length) {
|
||||
visible_idx.push(visible_idx.length);
|
||||
}
|
||||
|
||||
const args = {
|
||||
cmd: "frappe.desk.query_report.export_query",
|
||||
report_name: this.report_name,
|
||||
custom_columns: this.custom_columns.length ? this.custom_columns : [],
|
||||
custom_columns: this.custom_columns?.length ? this.custom_columns : [],
|
||||
file_format_type: file_format,
|
||||
filters: filters,
|
||||
applied_filters: applied_filters,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
"fast-deep-equal": "^2.0.1",
|
||||
"fast-glob": "^3.2.5",
|
||||
"frappe-charts": "2.0.0-rc22",
|
||||
"frappe-datatable": "1.17.14",
|
||||
"frappe-datatable": "1.17.15",
|
||||
"frappe-gantt": "^0.6.0",
|
||||
"highlight.js": "^10.4.1",
|
||||
"html5-qrcode": "^2.3.8",
|
||||
|
|
|
|||
|
|
@ -1483,10 +1483,10 @@ frappe-charts@2.0.0-rc22:
|
|||
resolved "https://registry.yarnpkg.com/frappe-charts/-/frappe-charts-2.0.0-rc22.tgz#9a5a747febdc381a1d4d7af96e89cf519dfba8c0"
|
||||
integrity sha512-N7f/8979wJCKjusOinaUYfMxB80YnfuVLrSkjpj4LtyqS0BGS6SuJxUnb7Jl4RWUFEIs7zEhideIKnyLeFZF4Q==
|
||||
|
||||
frappe-datatable@1.17.14:
|
||||
version "1.17.14"
|
||||
resolved "https://registry.yarnpkg.com/frappe-datatable/-/frappe-datatable-1.17.14.tgz#5fe99fa45089d6f2a54d13215608ef777bc947ec"
|
||||
integrity sha512-rrUyk+8ueX9ADDXwaHobBGmAWK86lF3P3yc3KYGHyhNiNTwKpUW08zQeuTUzJnWv0OSZ/zXYePzrjFKG7ZR4Wg==
|
||||
frappe-datatable@1.17.15:
|
||||
version "1.17.15"
|
||||
resolved "https://registry.yarnpkg.com/frappe-datatable/-/frappe-datatable-1.17.15.tgz#c1665b1ca2c1446a3a239f2b2a985a6df0c9a789"
|
||||
integrity sha512-/Zj5vwjUXX8UB/aC/oRvgZuSSj2saoKO1ux+w1MbUmhqK5B/sutct40Y+Nv/9+HAJswCb1UG6jNVa2IxUaGHQg==
|
||||
dependencies:
|
||||
hyperlist "^1.0.0-beta"
|
||||
lodash "^4.17.5"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue