浏览代码

[minor] added error log if there is any exception in email alert (#3335)

version-14
Makarand Bauskar 8 年前
committed by Rushabh Mehta
父节点
当前提交
6069751b1e
共有 1 个文件被更改,包括 42 次插入42 次删除
  1. +42
    -42
      frappe/email/doctype/email_alert/email_alert.py

+ 42
- 42
frappe/email/doctype/email_alert/email_alert.py 查看文件

@@ -112,55 +112,52 @@ def get_context(context):
context = get_context(doc)
recipients = []

try:
for recipient in self.recipients:
if recipient.condition:
if not frappe.safe_eval(recipient.condition, None, context):
continue
if recipient.email_by_document_field:
if validate_email_add(doc.get(recipient.email_by_document_field)):
recipient.email_by_document_field = doc.get(recipient.email_by_document_field).replace(",", "\n")
recipients = recipients + recipient.email_by_document_field.split("\n")

# else:
# print "invalid email"
if recipient.cc:
recipient.cc = recipient.cc.replace(",", "\n")
recipients = recipients + recipient.cc.split("\n")

#For sending emails to specified role
if recipient.email_by_role:
emails = get_emails_from_role(recipient.email_by_role)

for email in emails:
recipients = recipients + email.split("\n")

if not recipients:
return
for recipient in self.recipients:
if recipient.condition:
if not frappe.safe_eval(recipient.condition, None, context):
continue
if recipient.email_by_document_field:
if validate_email_add(doc.get(recipient.email_by_document_field)):
recipient.email_by_document_field = doc.get(recipient.email_by_document_field).replace(",", "\n")
recipients = recipients + recipient.email_by_document_field.split("\n")

# else:
# print "invalid email"
if recipient.cc:
recipient.cc = recipient.cc.replace(",", "\n")
recipients = recipients + recipient.cc.split("\n")

#For sending emails to specified role
if recipient.email_by_role:
emails = get_emails_from_role(recipient.email_by_role)

for email in emails:
recipients = recipients + email.split("\n")

if not recipients:
return

recipients = list(set(recipients))
subject = self.subject
recipients = list(set(recipients))
subject = self.subject

context = {"doc": doc, "alert": self, "comments": None}
context = {"doc": doc, "alert": self, "comments": None}

if self.is_standard:
self.load_standard_properties(context)
if self.is_standard:
self.load_standard_properties(context)

if doc.get("_comments"):
context["comments"] = json.loads(doc.get("_comments"))
if doc.get("_comments"):
context["comments"] = json.loads(doc.get("_comments"))

if "{" in subject:
subject = frappe.render_template(self.subject, context)
if "{" in subject:
subject = frappe.render_template(self.subject, context)

attachments = get_attachment(doc)
attachments = get_attachment(doc)

frappe.sendmail(recipients=recipients, subject=subject,
message= frappe.render_template(self.message, context),
reference_doctype = doc.doctype,
reference_name = doc.name,
attachments = attachments)
except Exception:
frappe.throw("Error in Email Alert")
frappe.sendmail(recipients=recipients, subject=subject,
message= frappe.render_template(self.message, context),
reference_doctype = doc.doctype,
reference_name = doc.name,
attachments = attachments)

def load_standard_properties(self, context):
module = get_doc_module(self.module, self.doctype, self.name)
@@ -239,6 +236,9 @@ def evaluate_alert(doc, alert, event):
alert.send(doc)
except TemplateError:
frappe.throw(_("Error while evaluating Email Alert {0}. Please fix your template.").format(alert))
except Exception, e:
frappe.log_error(message=frappe.get_traceback(), title=e)
frappe.throw("Error in Email Alert")

def get_context(doc):
return {"doc": doc, "nowdate": nowdate, "frappe.utils": frappe.utils}

正在加载...
取消
保存