瀏覽代碼

[fix] disable email alert on wrong field. fixes frappe/erpnext#3372 (#3290)

version-14
Rushabh Mehta 8 年之前
committed by Nabin Hait
父節點
當前提交
9abcaff48a
共有 3 個文件被更改,包括 39 次插入1 次删除
  1. +8
    -1
      frappe/email/doctype/email_alert/email_alert.py
  2. +30
    -0
      frappe/email/doctype/email_alert/test_email_alert.py
  3. +1
    -0
      frappe/exceptions.py

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

@@ -217,7 +217,14 @@ def evaluate_alert(doc, alert, event):
return

if event=="Value Change" and not doc.is_new():
db_value = frappe.db.get_value(doc.doctype, doc.name, alert.value_changed)
try:
db_value = frappe.db.get_value(doc.doctype, doc.name, alert.value_changed)
except frappe.DatabaseOperationalError as e:
if e.args[0]==1054:
alert.db_set('enabled', 0)
frappe.log_error('Email Alert {0} has been disabled due to missing field'.format(alert.name))
return

db_value = parse_val(db_value)
if (doc.get(alert.value_changed) == db_value) or \
(not db_value and not doc.get(alert.value_changed)):


+ 30
- 0
frappe/email/doctype/email_alert/test_email_alert.py 查看文件

@@ -87,6 +87,36 @@ class TestEmailAlert(unittest.TestCase):
self.assertTrue(frappe.db.get_value("Email Queue", {"reference_doctype": "Event",
"reference_name": event.name, "status":"Not Sent"}))

def test_alert_disabled_on_wrong_field(self):
frappe.set_user('Administrator')
email_alert = frappe.get_doc({
"doctype": "Email Alert",
"subject":"_Test Email Alert for wrong field",
"document_type": "Event",
"event": "Value Change",
"attach_print": 0,
"value_changed": "description1",
"message": "Description changed",
"recipients": [
{ "email_by_document_field": "owner" }
]
}).insert()

event = frappe.new_doc("Event")
event.subject = "test-2",
event.event_type = "Private"
event.starts_on = "2014-06-06 12:00:00"
event.insert()
event.subject = "test 1"
event.save()

# verify that email_alert is disabled
email_alert.reload()
self.assertEqual(email_alert.enabled, 0)
email_alert.delete()
event.delete()


def test_date_changed(self):
event = frappe.new_doc("Event")
event.subject = "test",


+ 1
- 0
frappe/exceptions.py 查看文件

@@ -7,6 +7,7 @@ from __future__ import unicode_literals

from werkzeug.exceptions import NotFound
from MySQLdb import ProgrammingError as SQLError, Error
from MySQLdb import OperationalError as DatabaseOperationalError


class ValidationError(Exception):


Loading…
取消
儲存