def evaluate_alert(doc, alert, event): from jinja2 import TemplateError try: if isinstance(alert, string_types): alert = frappe.get_doc("Telegram Notification", alert) context = get_context(doc) if alert.condition: if not frappe.safe_eval(alert.condition, None, context): return if event == "Value Change" and not doc.is_new(): try: db_value = frappe.db.get_value(doc.doctype, doc.name, alert.value_changed) except Exception as e: if frappe.db.is_missing_column(e): alert.db_set("enabled", 0) frappe.log_error( "Notification {0} has been disabled due to missing field" .format(alert.name)) return else: raise 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)): return # value not changed if event != "Value Change" and not doc.is_new(): # reload the doc for the latest values & comments, # except for validate type event. doc = frappe.get_doc(doc.doctype, doc.name) alert.send(doc) except TemplateError: frappe.throw( _("Error while evaluating Notification {0}. Please fix your template." ).format(alert)) except Exception as e: error_log = frappe.log_error(message=frappe.get_traceback(), title=str(e)) frappe.throw( _("Error in Notification: {}".format( frappe.utils.get_link_to_form("Error Log", error_log.name))))
def evaluate_alert(doc, alert, event): from jinja2 import TemplateError try: if isinstance(alert, string_types): alert = frappe.get_doc("Notification", alert) context = get_context(doc) if alert.condition: if not frappe.safe_eval(alert.condition, None, context): return if event == "Value Change" and not doc.is_new(): if not frappe.db.has_column(doc.doctype, alert.value_changed): alert.db_set('enabled', 0) frappe.log_error( 'Notification {0} has been disabled due to missing field'. format(alert.name)) return doc_before_save = doc.get_doc_before_save() field_value_before_save = doc_before_save.get( alert.value_changed) if doc_before_save else None field_value_before_save = parse_val(field_value_before_save) if (doc.get(alert.value_changed) == field_value_before_save): # value not changed return if event != "Value Change" and not doc.is_new(): # reload the doc for the latest values & comments, # except for validate type event. doc.reload() alert.send(doc) except TemplateError: frappe.throw( _("Error while evaluating Notification {0}. Please fix your template." ).format(alert)) except Exception as e: error_log = frappe.log_error(message=frappe.get_traceback(), title=str(e)) frappe.throw( _("Error in Notification: {}".format( frappe.utils.get_link_to_form('Error Log', error_log.name))))
def evaluate_alert(doc, alert, event): from jinja2 import TemplateError try: if isinstance(alert, string_types): alert = frappe.get_doc("Email Alert", alert) context = get_context(doc) if alert.condition: if not frappe.safe_eval(alert.condition, None, context): return if event == "Value Change" and not doc.is_new(): try: db_value = frappe.db.get_value(doc.doctype, doc.name, alert.value_changed) except pymysql.InternalError as e: if e.args[0] == ER.BAD_FIELD_ERROR: 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)): return # value not changed if event != "Value Change" and not doc.is_new(): # reload the doc for the latest values & comments, # except for validate type event. doc = frappe.get_doc(doc.doctype, doc.name) alert.send(doc) except TemplateError: frappe.throw( _("Error while evaluating Email Alert {0}. Please fix your template." ).format(alert)) except Exception as e: frappe.log_error(message=frappe.get_traceback(), title=e) frappe.throw(_("Error in Email Alert"))
def evaluate_alert(doc, alert, event): from jinja2 import TemplateError try: if isinstance(alert, string_types): alert = frappe.get_doc("Email Alert", alert) context = get_context(doc) if alert.condition: if not frappe.safe_eval(alert.condition, None, context): return if event=="Value Change" and not doc.is_new(): try: db_value = frappe.db.get_value(doc.doctype, doc.name, alert.value_changed) except pymysql.InternalError as e: if e.args[0]== ER.BAD_FIELD_ERROR: 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)): return # value not changed if event != "Value Change" and not doc.is_new(): # reload the doc for the latest values & comments, # except for validate type event. doc = frappe.get_doc(doc.doctype, doc.name) alert.send(doc) except TemplateError: frappe.throw(_("Error while evaluating Email Alert {0}. Please fix your template.").format(alert)) except Exception as e: frappe.log_error(message=frappe.get_traceback(), title=str(e)) frappe.throw(_("Error in Email Alert"))