diff --git a/frappe/core/doctype/email_alert/email_alert.js b/frappe/core/doctype/email_alert/email_alert.js index b7fb717063..7a44608464 100644 --- a/frappe/core/doctype/email_alert/email_alert.js +++ b/frappe/core/doctype/email_alert/email_alert.js @@ -1,6 +1,10 @@ frappe.email_alert = { setup_fieldname_select: function(frm) { // get the doctype to update fields + if(!frm.doc.document_type) { + return; + } + frappe.model.with_doctype(frm.doc.document_type, function() { var fields = frappe.get_doc("DocType", frm.doc.document_type).fields; @@ -9,10 +13,10 @@ frappe.email_alert = { function(d) { return in_list(frappe.model.no_value_type, d.fieldtype) ? null : d.fieldname; }); - options = "\n" + options.join("\n"); + options = options.join("\n"); // set value changed options - frm.set_df_property("value_changed", "options", options); + frm.set_df_property("value_changed", "options", "\n" + options); // set date changed options frm.set_df_property("date_changed", "options", $.map(fields, @@ -21,7 +25,7 @@ frappe.email_alert = { // set email recipient options frappe.meta.get_docfield("Email Alert Recipient", "email_by_document_field", - frm.doc.name).options = options; + frm.doc.name).options = "\nowner\n" + options; }); } diff --git a/frappe/core/doctype/email_alert/email_alert.json b/frappe/core/doctype/email_alert/email_alert.json index 5e29174184..14a171d755 100644 --- a/frappe/core/doctype/email_alert/email_alert.json +++ b/frappe/core/doctype/email_alert/email_alert.json @@ -47,6 +47,15 @@ "label": "Date Changed", "permlevel": 0 }, + { + "default": "0", + "depends_on": "eval:doc.event==\"Date Change\"", + "description": "[Optional] Send the email X days in advance of the specified date. 0 equals same day.", + "fieldname": "days_in_advance", + "fieldtype": "Int", + "label": "Days in Advance", + "permlevel": 0 + }, { "depends_on": "eval:doc.event==\"Value Change\"", "description": "Send alert if this field's value changes", @@ -111,7 +120,7 @@ } ], "icon": "icon-envelope", - "modified": "2014-07-14 12:55:10.467991", + "modified": "2014-07-14 15:33:46.806944", "modified_by": "Administrator", "module": "Core", "name": "Email Alert", diff --git a/frappe/core/doctype/email_alert/email_alert.py b/frappe/core/doctype/email_alert/email_alert.py index 3e28dd9a32..952e0b9cb0 100644 --- a/frappe/core/doctype/email_alert/email_alert.py +++ b/frappe/core/doctype/email_alert/email_alert.py @@ -25,7 +25,8 @@ def trigger_email_alerts(doc, method=None): alert = frappe.get_doc("Email Alert", alert) for name in frappe.db.sql_list("""select name from `tab%s` where - DATE(%s) = CURDATE()""" % (alert.document_type, alert.date_changed)): + DATE(%s) = ADDDATE(CURDATE(), INTERVAL %s DAY)""" % \ + (alert.document_type, alert.date_changed, alert.days_in_advance or 0)): evaluate_alert(frappe.get_doc(alert.document_type, name), alert, "Date Change") diff --git a/frappe/core/doctype/email_alert/test_email_alert.py b/frappe/core/doctype/email_alert/test_email_alert.py index 8b9bbc8582..a48e2736b3 100644 --- a/frappe/core/doctype/email_alert/test_email_alert.py +++ b/frappe/core/doctype/email_alert/test_email_alert.py @@ -84,7 +84,7 @@ class TestEmailAlert(unittest.TestCase): self.assertFalse(frappe.db.get_value("Bulk Email", {"ref_doctype": "Event", "ref_docname": event.name, "status":"Not Sent"})) - event.starts_on = frappe.utils.now() + event.starts_on = frappe.utils.add_days(frappe.utils.nowdate(), 2) + " 12:00:00" event.save() self.assertFalse(frappe.db.get_value("Bulk Email", {"ref_doctype": "Event", diff --git a/frappe/core/doctype/email_alert/test_records.json b/frappe/core/doctype/email_alert/test_records.json index 39e4ee5bc7..dfe87aafe0 100644 --- a/frappe/core/doctype/email_alert/test_records.json +++ b/frappe/core/doctype/email_alert/test_records.json @@ -47,6 +47,7 @@ "document_type": "Event", "event": "Date Change", "date_changed": "starts_on", + "days_in_advance": 2, "message": "Description changed", "email_alert_recipients": [ { "email_by_document_field": "owner" }