From ba0045ef1fca220dc6320946e38cfbc7b6cb6480 Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Thu, 6 Dec 2018 18:12:34 +0530 Subject: [PATCH 1/2] communication: fix attachments in email queue and generated reports so, apparently i messed up some things that were responsible for handling file attachments in email queue and attached on-the-fly generated reports. these issues should be fixed now. Signed-off-by: Chinmay Pai --- frappe/core/doctype/communication/email.py | 2 +- frappe/email/queue.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py index 4864dd12c2..091adc3b4b 100755 --- a/frappe/core/doctype/communication/email.py +++ b/frappe/core/doctype/communication/email.py @@ -280,7 +280,7 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None) # is it a filename? try: # keep this for error handling - _file = frappe.get_doc("File", {"file_name": a}) + _file = frappe.get_doc("File", a) _file.get_content() # these attachments will be attached on-demand # and won't be stored in the message diff --git a/frappe/email/queue.py b/frappe/email/queue.py index 07433ed715..eb8edd8e2a 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -537,7 +537,7 @@ def prepare_message(email, recipient, recipients_list): fid = attachment.get("fid") if fid: - _file = frappe.get_doc("File", {"file_name": fid}) + _file = frappe.get_doc("File", fid) fcontent = _file.get_content() attachment.update({ 'fname': _file.file_name, From 25f5d65632112faf622ec8d728d7a2b33660e854 Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Thu, 6 Dec 2018 19:32:10 +0530 Subject: [PATCH 2/2] communication: handle attachment case for both filename and fileid some incoming files could have either filename or fileid for whatever reason. this handles both those cases (at least for now). Signed-off-by: Chinmay Pai --- frappe/core/doctype/communication/email.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py index 091adc3b4b..fbcd30a3f2 100755 --- a/frappe/core/doctype/communication/email.py +++ b/frappe/core/doctype/communication/email.py @@ -279,12 +279,16 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None) if isinstance(a, string_types): # is it a filename? try: - # keep this for error handling - _file = frappe.get_doc("File", a) + # check for both filename and file id + file_id = frappe.db.get_list('File', or_filters={'file_name': a, 'name': a}, limit=1) + if not file_id: + frappe.throw(_("Unable to find attachment {0}").format(a)) + file_id = file_id[0]['name'] + _file = frappe.get_doc("File", file_id) _file.get_content() # these attachments will be attached on-demand # and won't be stored in the message - doc.attachments.append({"fid": a}) + doc.attachments.append({"fid": file_id}) except IOError: frappe.throw(_("Unable to find attachment {0}").format(a)) else: