|
|
@@ -15,13 +15,21 @@ class EmailAlert(Document): |
|
|
|
if self.event=="Value Change" and not self.value_changed: |
|
|
|
frappe.throw(_("Please specify which value field must be checked")) |
|
|
|
|
|
|
|
forbidden_document_types = ("Bulk Email",) |
|
|
|
if self.document_type in forbidden_document_types: |
|
|
|
frappe.throw(_("Cannot set Email Alert on Document Type {0}").format(self.document_type)) |
|
|
|
|
|
|
|
def trigger_daily_alerts(): |
|
|
|
trigger_email_alerts(None, "Date Change") |
|
|
|
|
|
|
|
def trigger_email_alerts(doc, method=None): |
|
|
|
if frappe.flags.in_import or frappe.flags.in_patch: |
|
|
|
# don't send email alerts while syncing or patching |
|
|
|
return |
|
|
|
|
|
|
|
if method=="Date Change": |
|
|
|
for alert in frappe.db.sql_list("""select name from `tabEmail Alert` |
|
|
|
where event='Date Change'"""): |
|
|
|
where event='Date Change' and enabled=1"""): |
|
|
|
|
|
|
|
alert = frappe.get_doc("Email Alert", alert) |
|
|
|
|
|
|
@@ -46,7 +54,7 @@ def trigger_email_alerts(doc, method=None): |
|
|
|
}[method] |
|
|
|
|
|
|
|
for alert in frappe.db.sql_list("""select name from `tabEmail Alert` |
|
|
|
where document_type=%s and event=%s""", (doc.doctype, eevent)): |
|
|
|
where document_type=%s and event=%s and enabled=1""", (doc.doctype, eevent)): |
|
|
|
evaluate_alert(doc, alert, eevent) |
|
|
|
|
|
|
|
def evaluate_alert(doc, alert, event): |
|
|
@@ -86,7 +94,7 @@ def evaluate_alert(doc, alert, event): |
|
|
|
|
|
|
|
|
|
|
|
footer = """<div style='margin-top: 20px; font-size: 80%; color: #888'> |
|
|
|
This Email Alert {{alert.name}} was autogenerated for |
|
|
|
This Email Alert <em>{{alert.subject}}</em> was autogenerated for |
|
|
|
{{ doc.doctype }} <a href="/desk#Form/{{doc.doctype}}/{{doc.name}}">{{doc.name}}</a>. |
|
|
|
To update, modify it, go to Setup > Email > <a href="/desk#List/Email Alert">Email Alert</a> |
|
|
|
""" |