Merge pull request #13973 from deepeshgarg007/auto_email_report_null_values
fix: Handle null values in auto email report rows for XLSX format
This commit is contained in:
commit
e8623474da
2 changed files with 15 additions and 18 deletions
|
|
@ -391,7 +391,7 @@ def handle_duration_fieldtype_values(result, columns):
|
|||
return result
|
||||
|
||||
|
||||
def build_xlsx_data(columns, data, visible_idx, include_indentation):
|
||||
def build_xlsx_data(columns, data, visible_idx, include_indentation, ignore_visible_idx=False):
|
||||
result = [[]]
|
||||
column_widths = []
|
||||
|
||||
|
|
@ -407,7 +407,7 @@ def build_xlsx_data(columns, data, visible_idx, include_indentation):
|
|||
# build table from result
|
||||
for row_idx, row in enumerate(data.result):
|
||||
# only pick up rows that are visible in the report
|
||||
if row_idx in visible_idx:
|
||||
if ignore_visible_idx or row_idx in visible_idx:
|
||||
row_data = []
|
||||
if isinstance(row, dict):
|
||||
for col_idx, column in enumerate(data.columns):
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from frappe.utils import (format_time, get_link_to_form, get_url_to_report,
|
|||
from frappe.model.naming import append_number_if_name_exists
|
||||
from frappe.utils.csvutils import to_csv
|
||||
from frappe.utils.xlsxutils import make_xlsx
|
||||
from frappe.desk.query_report import build_xlsx_data
|
||||
|
||||
max_reports_per_user = frappe.local.conf.max_reports_per_user or 3
|
||||
|
||||
|
|
@ -99,13 +100,21 @@ class AutoEmailReport(Document):
|
|||
return self.get_html_table(columns, data)
|
||||
|
||||
elif self.format == 'XLSX':
|
||||
spreadsheet_data = self.get_spreadsheet_data(columns, data)
|
||||
xlsx_file = make_xlsx(spreadsheet_data, "Auto Email Report")
|
||||
report_data = frappe._dict()
|
||||
report_data['columns'] = columns
|
||||
report_data['result'] = data
|
||||
|
||||
xlsx_data, column_widths = build_xlsx_data(columns, report_data, [], 1, ignore_visible_idx=True)
|
||||
xlsx_file = make_xlsx(xlsx_data, "Auto Email Report", column_widths=column_widths)
|
||||
return xlsx_file.getvalue()
|
||||
|
||||
elif self.format == 'CSV':
|
||||
spreadsheet_data = self.get_spreadsheet_data(columns, data)
|
||||
return to_csv(spreadsheet_data)
|
||||
report_data = frappe._dict()
|
||||
report_data['columns'] = columns
|
||||
report_data['result'] = data
|
||||
|
||||
xlsx_data, column_widths = build_xlsx_data(columns, report_data, [], 1, ignore_visible_idx=True)
|
||||
return to_csv(xlsx_data)
|
||||
|
||||
else:
|
||||
frappe.throw(_('Invalid Output Format'))
|
||||
|
|
@ -126,18 +135,6 @@ class AutoEmailReport(Document):
|
|||
'edit_report_settings': get_link_to_form('Auto Email Report', self.name)
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def get_spreadsheet_data(columns, data):
|
||||
out = [[_(df.label) for df in columns], ]
|
||||
for row in data:
|
||||
new_row = []
|
||||
out.append(new_row)
|
||||
for df in columns:
|
||||
if df.fieldname not in row: continue
|
||||
new_row.append(frappe.format(row[df.fieldname], df, row))
|
||||
|
||||
return out
|
||||
|
||||
def get_file_name(self):
|
||||
return "{0}.{1}".format(self.report.replace(" ", "-").replace("/", "-"), self.format.lower())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue