'Run email alerts for this method'

def run_email_alerts(self, method):

    if (frappe.flags.in_import or frappe.flags.in_patch or frappe.flags.in_install):
        return
    if (self.flags.email_alerts_executed == None):
        self.flags.email_alerts_executed = []
    from frappe.email.doctype.email_alert.email_alert import evaluate_alert
    if (self.flags.email_alerts == None):
        alerts = frappe.cache().hget(u'email_alerts', self.doctype)
        if (alerts == None):
            alerts = frappe.get_all(u'Email    Alert', fields=[u'name', u'event', u'method'], filters={u'enabled': 1, u'document_type': self.doctype})
            frappe.cache().hset(u'email_alerts', self.doctype, alerts)
        self.flags.email_alerts = alerts
    if (not self.flags.email_alerts):
        return
    def _evaluate_alert(alert):
        if (not (alert.name in self.flags.email_alerts_executed)):
            evaluate_alert(self, alert.name, alert.event)
            self.flags.email_alerts_executed.append(alert.name)
    event_map = {u'on_update': u'Save', u'after_insert': u'New', u'on_submit': u'Submit', u'on_cancel': u'Cancel'}
    if (not self.flags.in_insert):
        event_map[u'validate'] = u'Value    Change'
        event_map[u'before_change'] = u'Value    Change'
        event_map[u'before_update_after_submit'] = u'Value    Change'
    for alert in self.flags.email_alerts:
        event = event_map.get(method, None)
        if (event and (alert.event == event)):
            _evaluate_alert(alert)
        elif ((alert.event == u'Method') and (method == alert.method)):
            _evaluate_alert(alert)
