fix: added option to show indentation (#7855)
* fix: added option to show indentation * fix: if check
This commit is contained in:
parent
c1f2e18591
commit
02d63dcc4f
3 changed files with 16 additions and 9 deletions
|
|
@ -307,6 +307,7 @@ def export_query():
|
|||
if isinstance(data.get("file_format_type"), string_types):
|
||||
file_format_type = data["file_format_type"]
|
||||
|
||||
include_indentation = data["include_indentation"]
|
||||
if isinstance(data.get("visible_idx"), string_types):
|
||||
visible_idx = json.loads(data.get("visible_idx"))
|
||||
else:
|
||||
|
|
@ -318,7 +319,7 @@ def export_query():
|
|||
columns = get_columns_dict(data.columns)
|
||||
|
||||
from frappe.utils.xlsxutils import make_xlsx
|
||||
xlsx_data = build_xlsx_data(columns, data, visible_idx)
|
||||
xlsx_data = build_xlsx_data(columns, data, visible_idx, include_indentation)
|
||||
xlsx_file = make_xlsx(xlsx_data, "Query Report")
|
||||
|
||||
frappe.response['filename'] = report_name + '.xlsx'
|
||||
|
|
@ -326,7 +327,7 @@ def export_query():
|
|||
frappe.response['type'] = 'binary'
|
||||
|
||||
|
||||
def build_xlsx_data(columns, data, visible_idx):
|
||||
def build_xlsx_data(columns, data, visible_idx,include_indentation):
|
||||
result = [[]]
|
||||
|
||||
# add column headings
|
||||
|
|
@ -344,7 +345,7 @@ def build_xlsx_data(columns, data, visible_idx):
|
|||
label = columns[idx]["label"]
|
||||
fieldname = columns[idx]["fieldname"]
|
||||
cell_value = row.get(fieldname, row.get(label, ""))
|
||||
if 'indent' in row and idx == 0:
|
||||
if cint(include_indentation) and 'indent' in row and idx == 0:
|
||||
cell_value = (' ' * cint(row['indent'])) + cell_value
|
||||
row_data.append(cell_value)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -889,11 +889,16 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
options: ['Excel', 'CSV'],
|
||||
default: 'Excel',
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
label: __("Include indentation"),
|
||||
fieldname: "include_indentation",
|
||||
fieldtype: "Check",
|
||||
}
|
||||
], ({ file_format }) => {
|
||||
], ({ file_format, include_indentation }) => {
|
||||
if (file_format === 'CSV') {
|
||||
const column_row = this.columns.map(col => col.label);
|
||||
const data = this.get_data_for_csv();
|
||||
const data = this.get_data_for_csv(include_indentation);
|
||||
const out = [column_row].concat(data);
|
||||
|
||||
frappe.tools.downloadify(out, null, this.report_name);
|
||||
|
|
@ -914,6 +919,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
file_format_type: file_format,
|
||||
filters: filters,
|
||||
visible_idx,
|
||||
include_indentation,
|
||||
};
|
||||
|
||||
open_url_post(frappe.request.url, args);
|
||||
|
|
@ -921,7 +927,7 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
}, __('Export Report: '+ this.report_name), __('Download'));
|
||||
}
|
||||
|
||||
get_data_for_csv() {
|
||||
get_data_for_csv(include_indentation) {
|
||||
const indices = this.datatable.bodyRenderer.visibleRowIndices;
|
||||
const rows = indices.map(i => this.datatable.datamanager.getRow(i));
|
||||
return rows.map(row => {
|
||||
|
|
@ -929,8 +935,8 @@ frappe.views.QueryReport = class QueryReport extends frappe.views.BaseList {
|
|||
return row
|
||||
.slice(standard_column_count)
|
||||
.map((cell, i) => {
|
||||
if (i === 0) {
|
||||
return ' '.repeat(row.meta.indent) + (cell.content || '');
|
||||
if (include_indentation && i===0) {
|
||||
cell.content = ' '.repeat(row.meta.indent) + (cell.content || '');
|
||||
}
|
||||
return cell.content || '';
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class TestQueryReport(unittest.TestCase):
|
|||
visible_idx = [0, 2, 3]
|
||||
|
||||
# Build the result
|
||||
xlsx_data = build_xlsx_data(columns, data, visible_idx)
|
||||
xlsx_data = build_xlsx_data(columns, data, visible_idx, include_indentation=0)
|
||||
|
||||
self.assertEqual(type(xlsx_data), list)
|
||||
self.assertEqual(len(xlsx_data), 4) # columns + data
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue