feat: meaningful report pdf name (#18422)
* feat: meaningful report pdf name * feat: limited filename length * chore: uncomment line
This commit is contained in:
parent
fce9ccedaa
commit
f383669107
2 changed files with 20 additions and 2 deletions
|
|
@ -175,6 +175,7 @@ frappe.render_template = function (name, data) {
|
|||
w.document.write(tree);
|
||||
w.document.close();
|
||||
});
|
||||
|
||||
frappe.render_pdf = function (html, opts = {}) {
|
||||
//Create a form to place the HTML content
|
||||
var formData = new FormData();
|
||||
|
|
@ -197,8 +198,17 @@ frappe.render_pdf = function (html, opts = {}) {
|
|||
var blob = new Blob([success.currentTarget.response], { type: "application/pdf" });
|
||||
var objectUrl = URL.createObjectURL(blob);
|
||||
|
||||
//Open report in a new window
|
||||
window.open(objectUrl);
|
||||
// Create a hidden a tag to force set report name
|
||||
// https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link
|
||||
let hidden_a_tag = document.createElement("a");
|
||||
document.body.appendChild(hidden_a_tag);
|
||||
hidden_a_tag.style = "display: none";
|
||||
hidden_a_tag.href = objectUrl;
|
||||
hidden_a_tag.download = opts.report_name || "report.pdf";
|
||||
|
||||
// Open report in a new window
|
||||
hidden_a_tag.click();
|
||||
window.URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
|
|
|
|||
|
|
@ -1383,6 +1383,14 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
layout_direction: frappe.utils.is_rtl() ? "rtl" : "ltr",
|
||||
});
|
||||
|
||||
let filter_values = [],
|
||||
name_len = 0;
|
||||
for (var key of Object.keys(applied_filters)) {
|
||||
name_len = name_len + applied_filters[key].toString().length;
|
||||
if (name_len > 200) break;
|
||||
filter_values.push(applied_filters[key]);
|
||||
}
|
||||
print_settings.report_name = `${__(this.report_name)}_${filter_values.join("_")}.pdf`;
|
||||
frappe.render_pdf(html, print_settings);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue