attach print format in the emails before sending. (#4366)
This commit is contained in:
parent
7fa97e97fe
commit
a279cdc4a2
3 changed files with 26 additions and 15 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 = []
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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)
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue