diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py index ac69cc24e2..2188a808c0 100755 --- a/frappe/core/doctype/communication/email.py +++ b/frappe/core/doctype/communication/email.py @@ -259,8 +259,8 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None) doc.attachments = [] if print_html or print_format: - doc.attachments.append(frappe.attach_print(doc.reference_doctype, doc.reference_name, - print_format=print_format, html=print_html)) + doc.attachments.append({"print_format_attachment":1, "doctype":doc.reference_doctype, + "name":doc.reference_name, "print_format":print_format, "html":print_html}) if attachments: if isinstance(attachments, string_types): @@ -270,8 +270,11 @@ 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 = get_file(a) - doc.attachments.append({"fname": file[0], "fcontent": file[1]}) + # these attachments will be attached on-demand + # and won't be stored in the message + doc.attachments.append({"fid": a}) except IOError: frappe.throw(_("Unable to find attachment {0}").format(a)) else: diff --git a/frappe/email/doctype/email_alert/email_alert.py b/frappe/email/doctype/email_alert/email_alert.py index 10a964d88f..93208b7e12 100755 --- a/frappe/email/doctype/email_alert/email_alert.py +++ b/frappe/email/doctype/email_alert/email_alert.py @@ -117,7 +117,8 @@ def get_context(context): please enable Allow Print For {0} in Print Settings""".format(status)), title=_("Error in Email Alert")) else: - return [frappe.attach_print(doc.doctype, doc.name, None, self.print_format)] + return [{"print_format_attachment":1, "doctype":doc.doctype, "name": doc.name, + "print_format":self.print_format}] context = get_context(doc) recipients = [] diff --git a/frappe/email/queue.py b/frappe/email/queue.py index 91ac4cf06a..085dfb0c18 100755 --- a/frappe/email/queue.py +++ b/frappe/email/queue.py @@ -162,11 +162,13 @@ def get_email_queue(recipients, sender, subject, **kwargs): e.priority = kwargs.get('send_priority') attachments = kwargs.get('attachments') if attachments: - # store attachments with fid, to be attached on-demand later + # store attachments with fid or print format details, to be attached on-demand later _attachments = [] for att in attachments: if att.get('fid'): _attachments.append(att) + elif att.get("print_format_attachment") == 1: + _attachments.append(att) e.attachments = json.dumps(_attachments) try: @@ -517,17 +519,22 @@ def prepare_message(email, recipient, recipients_list): for attachment in attachments: if attachment.get('fcontent'): continue - fid = attachment.get('fid') - if not fid: continue - - fname, fcontent = get_file(fid) - attachment.update({ - 'fname': fname, - 'fcontent': fcontent, - 'parent': msg_obj - }) - attachment.pop("fid", None) - add_attachment(**attachment) + fid = attachment.get("fid") + if fid: + fname, fcontent = get_file(fid) + attachment.update({ + 'fname': fname, + 'fcontent': fcontent, + 'parent': msg_obj + }) + attachment.pop("fid", None) + add_attachment(**attachment) + + elif attachment.get("print_format_attachment") == 1: + attachment.pop("print_format_attachment", None) + print_format_file = frappe.attach_print(**attachment) + print_format_file.update({"parent": msg_obj}) + add_attachment(**print_format_file) return msg_obj.as_string()