From 8890165fa33d4e08ebaeede707492def343ec2d0 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 30 May 2017 15:22:25 +0530 Subject: [PATCH] Multiple issues fixed in auto email report (#3394) --- frappe/core/doctype/report/report.py | 17 +++++++++++------ frappe/desk/query_report.py | 13 ++++++++----- .../auto_email_report/auto_email_report.py | 6 +++--- frappe/email/queue.py | 3 ++- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/frappe/core/doctype/report/report.py b/frappe/core/doctype/report/report.py index 3757f581e9..8c3e61d55f 100644 --- a/frappe/core/doctype/report/report.py +++ b/frappe/core/doctype/report/report.py @@ -100,12 +100,18 @@ class Report(Document): data = frappe.desk.query_report.run(self.name, filters=filters, user=user) for d in data.get('columns'): if isinstance(d, dict): - columns.append(frappe._dict(d)) + col = frappe._dict(d) + if not col.fieldname: + col.fieldname = col.label + columns.append(col) else: + fieldtype, options = "Data", None parts = d.split(':') - fieldtype, options = parts[1], None - if fieldtype and '/' in fieldtype: - fieldtype, options = fieldtype.split('/') + if len(parts) > 1: + if parts[1]: + fieldtype, options = parts[1], None + if fieldtype and '/' in fieldtype: + fieldtype, options = fieldtype.split('/') columns.append(frappe._dict(label=parts[0], fieldtype=fieldtype, fieldname=parts[0])) @@ -145,7 +151,7 @@ class Report(Document): for c in columns] out = out + [list(d) for d in result] - + if as_dict: data = [] for row in out: @@ -155,7 +161,6 @@ class Report(Document): _row[columns[i].get('fieldname')] = val else: data = out - return columns, data diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index bf38eea6a8..096467f9f8 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -104,7 +104,7 @@ def run(report_name, filters=None, user=None): if cint(report.add_total_row) and result: result = add_total_row(result, columns) - + return { "result": result, "columns": columns, @@ -185,9 +185,12 @@ def add_total_row(result, columns, meta = None): else: col = col.split(":") if len(col) > 1: - fieldtype = col[1] - if "/" in fieldtype: - fieldtype, options = fieldtype.split("/") + if col[1]: + fieldtype = col[1] + if "/" in fieldtype: + fieldtype, options = fieldtype.split("/") + else: + fieldtype = "Data" else: fieldtype = col.get("fieldtype") options = col.get("options") @@ -213,7 +216,7 @@ def add_total_row(result, columns, meta = None): else: first_col_fieldtype = columns[0].get("fieldtype") - if first_col_fieldtype not in ["Currency", "Int", "Float", "Percent"]: + if first_col_fieldtype not in ["Currency", "Int", "Float", "Percent", "Date"]: if first_col_fieldtype == "Link": total_row[0] = "'" + _("Total") + "'" else: diff --git a/frappe/email/doctype/auto_email_report/auto_email_report.py b/frappe/email/doctype/auto_email_report/auto_email_report.py index a6238865ff..3b752b4c2b 100644 --- a/frappe/email/doctype/auto_email_report/auto_email_report.py +++ b/frappe/email/doctype/auto_email_report/auto_email_report.py @@ -124,9 +124,9 @@ class AutoEmailReport(Document): report_doctype = frappe.db.get_value('Report', self.report, 'ref_doctype') report_footer = frappe.render_template(self.get_report_footer(), - dict(report_url = frappe.utils.get_url_to_report(self.report, self.report_type, report_doctype), - report_name = self.report, - edit_report_settings = frappe.utils.get_link_to_form('Auto Email Report', self.name))) + dict(report_url = frappe.utils.get_url_to_report(self.report, self.report_type, report_doctype), + report_name = self.report, + edit_report_settings = frappe.utils.get_link_to_form('Auto Email Report', self.name))) message += report_footer diff --git a/frappe/email/queue.py b/frappe/email/queue.py index 1ae2af56bd..c153a3cec6 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -432,7 +432,8 @@ def prepare_message(email, recipient, recipients_list): if email.add_unsubscribe_link and email.reference_doctype: # is missing the check for unsubscribe message but will not add as there will be no unsubscribe url unsubscribe_url = get_unsubcribed_url(email.reference_doctype, email.reference_name, recipient, email.unsubscribe_method, email.unsubscribe_params) - message = message.replace("", quopri.encodestring(unsubscribe_url)) + if message: + message = message.replace("", quopri.encodestring(unsubscribe_url)) if email.expose_recipients == "header": pass