瀏覽代碼

attach print format in the emails before sending. (#4366)

version-14
Manas Solanki 7 年之前
committed by Rushabh Mehta
父節點
當前提交
a279cdc4a2
共有 3 個文件被更改,包括 27 次插入16 次删除
  1. +6
    -3
      frappe/core/doctype/communication/email.py
  2. +2
    -1
      frappe/email/doctype/email_alert/email_alert.py
  3. +19
    -12
      frappe/email/queue.py

+ 6
- 3
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 = [] 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:


+ 2
- 1
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)), 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 = []


+ 19
- 12
frappe/email/queue.py 查看文件

@@ -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()




Loading…
取消
儲存