Skip to content

Commit

Permalink
fix: allow exporting large reports that can't be rendered (backport #…
Browse files Browse the repository at this point in the history
…25395) (#25404)

* fix: dont render very large reports, offer export instead

(cherry picked from commit 65fb8dc)

# Conflicts:
#	frappe/public/js/frappe/views/reports/query_report.js

* chore: conflicts

* fix: make excel export work without rendering

* fix: hide CSV option if not available

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 14, 2024
1 parent de5a2b3 commit b3f4d5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frappe/desk/query_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def build_xlsx_data(data, visible_idx, include_indentation, ignore_visible_idx=F
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:
Expand Down
45 changes: 32 additions & 13 deletions frappe/public/js/frappe/views/reports/query_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,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(
Expand Down Expand Up @@ -937,6 +941,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);
Expand Down Expand Up @@ -1453,12 +1467,17 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
return;
}

let export_options = ["Excel"];
if (this.datatable) {
export_options.push("CSV");
}

let export_dialog_fields = [
{
label: __("Select File Format"),
fieldname: "file_format",
fieldtype: "Select",
options: ["Excel", "CSV"],
options: export_options,
default: "Excel",
reqd: 1,
},
Expand Down Expand Up @@ -1496,15 +1515,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,
visible_idx,
Expand Down

0 comments on commit b3f4d5d

Please sign in to comment.