Просмотр исходного кода

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

version-14
Rushabh Mehta 8 лет назад
committed by Nabin Hait
Родитель
Сommit
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 return


if event=="Value Change" and not doc.is_new(): 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) db_value = parse_val(db_value)
if (doc.get(alert.value_changed) == db_value) or \ if (doc.get(alert.value_changed) == db_value) or \
(not db_value and not doc.get(alert.value_changed)): (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", self.assertTrue(frappe.db.get_value("Email Queue", {"reference_doctype": "Event",
"reference_name": event.name, "status":"Not Sent"})) "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): def test_date_changed(self):
event = frappe.new_doc("Event") event = frappe.new_doc("Event")
event.subject = "test", event.subject = "test",


+ 1
- 0
frappe/exceptions.py Просмотреть файл

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


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




class ValidationError(Exception): class ValidationError(Exception):


Загрузка…
Отмена
Сохранить