@@ -259,8 +259,8 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None) | |||||
doc.attachments = [] | doc.attachments = [] | ||||
if print_html or print_format: | 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 attachments: | ||||
if isinstance(attachments, string_types): | 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): | if isinstance(a, string_types): | ||||
# is it a filename? | # is it a filename? | ||||
try: | try: | ||||
# keep this for error handling | |||||
file = get_file(a) | 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: | except IOError: | ||||
frappe.throw(_("Unable to find attachment {0}").format(a)) | frappe.throw(_("Unable to find attachment {0}").format(a)) | ||||
else: | else: | ||||
@@ -117,7 +117,8 @@ def get_context(context): | |||||
please enable Allow Print For {0} in Print Settings""".format(status)), | please enable Allow Print For {0} in Print Settings""".format(status)), | ||||
title=_("Error in Email Alert")) | title=_("Error in Email Alert")) | ||||
else: | 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) | context = get_context(doc) | ||||
recipients = [] | recipients = [] | ||||
@@ -162,11 +162,13 @@ def get_email_queue(recipients, sender, subject, **kwargs): | |||||
e.priority = kwargs.get('send_priority') | e.priority = kwargs.get('send_priority') | ||||
attachments = kwargs.get('attachments') | attachments = kwargs.get('attachments') | ||||
if 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 = [] | _attachments = [] | ||||
for att in attachments: | for att in attachments: | ||||
if att.get('fid'): | if att.get('fid'): | ||||
_attachments.append(att) | _attachments.append(att) | ||||
elif att.get("print_format_attachment") == 1: | |||||
_attachments.append(att) | |||||
e.attachments = json.dumps(_attachments) | e.attachments = json.dumps(_attachments) | ||||
try: | try: | ||||
@@ -517,17 +519,22 @@ def prepare_message(email, recipient, recipients_list): | |||||
for attachment in attachments: | for attachment in attachments: | ||||
if attachment.get('fcontent'): continue | 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() | return msg_obj.as_string() | ||||