added days in advance

This commit is contained in:
Rushabh Mehta 2014-07-14 15:40:46 +05:30 committed by Anand Doshi
parent b9f6bc3423
commit 25d10c5b73
5 changed files with 21 additions and 6 deletions

View file

@ -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;
});
}

View file

@ -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",

View file

@ -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")

View file

@ -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",

View file

@ -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" }