');
- }
- })();
- if(res.send) {
- var print_heading = (doc.select_print_heading || args['type'])
- if(validate_email(args['send_to'] || doc.contact_email || '')) {
- sendmail(
- args['send_to'] || doc.contact_email,
- send_from,
- send_from,
- doc.company + " - " + print_heading + " - " + doc.name,
- res.message,
- res.print_format
- );
- msgprint('This ' + print_heading + ' is being sent to '
- + (args['send_to'] || doc.contact_email) + '
...');
- } else {
- msgprint('Invalid/Missing Email Address of Contact. Auto notification for '
- + print_heading + ' not sent.');
- }
- }
- }
- //console.log(JSON.parse(r.message));
- });
+ }
}
diff --git a/setup/doctype/notification_control/notification_control.py b/setup/doctype/notification_control/notification_control.py
index f8b0ee2ad5a..b40ba6e2b09 100644
--- a/setup/doctype/notification_control/notification_control.py
+++ b/setup/doctype/notification_control/notification_control.py
@@ -25,84 +25,17 @@ from webnotes import msgprint
sql = webnotes.conn.sql
-# -----------------------------------------------------------------------------------------
-# Notification control
class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
- # get message to load in custom text
- # ----------------------------------
def get_message(self, arg):
fn = arg.lower().replace(' ', '_') + '_message'
v = sql("select value from tabSingles where field=%s and doctype=%s", (fn, 'Notification Control'))
return v and v[0][0] or ''
- # set custom text
- # ---------------
def set_message(self, arg = ''):
fn = self.doc.select_transaction.lower().replace(' ', '_') + '_message'
webnotes.conn.set(self.doc, fn, self.doc.custom_message)
msgprint("Custom Message for %s updated!" % self.doc.select_transaction)
-
- def get_formatted_message(self, args):
- """
- args can contain:
- * type
- * doctype
- * contact_name
- """
- import json
- args = json.loads(args)
- res = {
- 'send': 0,
- 'message': self.prepare_message(args),
- 'print_format': self.get_default_print_format(args)
- }
-
- dt_small = args.get('doctype').replace(' ', '_').lower()
- if cint(self.doc.fields.get(dt_small)):
- res['send'] = 1
-
- return json.dumps(res)
-
-
- def prepare_message(self, args):
- """
- Prepares message body
- """
- if args.get('type'):
- msg_dict = {}
- msg_dict['message'] = args.get('message') or self.get_message(args.get('type'))
- msg_dict['company'] = Document('Control Panel', 'Control Panel').company_name
- msg_dict['salutation'] = "Hi" + (args.get('contact_name') and (" " + args.get('contact_name')) or "")
- msg_dict['send_from'] = webnotes.conn.sql("""\
- SELECT CONCAT_WS(' ', first_name, last_name)
- FROM `tabProfile`
- WHERE name = %s""", webnotes.session['user'], as_list=1)[0][0] or ''
-
- return """\
-
- %(salutation)s,
-
- %(message)s
-
- Thanks,
- %(send_from)s
- %(company)s
-
""" % msg_dict
-
- else: return ""
-
-
- def get_default_print_format(self, args):
- """
- Get default print format from doclayer
- """
- doclayer = get_obj('Customize Form', 'Customize Form')
- doclayer.doc.doc_type = args.get('doctype')
- doclayer.get()
- if doclayer.doc.default_print_format:
- return doclayer.doc.default_print_format
- else: return 'Standard'
diff --git a/startup/event_handlers.py b/startup/event_handlers.py
index 7d1f5847c0b..07205b8814e 100644
--- a/startup/event_handlers.py
+++ b/startup/event_handlers.py
@@ -76,6 +76,8 @@ def boot_session(bootinfo):
import webnotes.model.doctype
bootinfo['docs'] += webnotes.model.doctype.get('Event')
bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria')
+ bootinfo['notification_settings'] = webnotes.doc("Notification Control",
+ "Notification Control").get_values()
bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')
diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js
index 4a3910abecb..62958112a1c 100644
--- a/stock/doctype/delivery_note/delivery_note.js
+++ b/stock/doctype/delivery_note/delivery_note.js
@@ -23,7 +23,6 @@ cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
// ONLOAD
// ================================================================================================
@@ -327,9 +326,7 @@ cur_frm.pformat.sales_order_no= function(doc, cdt, cdn){
}
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
- var args = {
- type: 'Delivery Note',
- doctype: 'Delivery Note'
+ if(cint(wn.boot.notification_settings.delivery_note)) {
+ cur_frm.email_doc(wn.boot.notification_settings.delivery_note);
}
- cur_frm.cscript.notify(doc, args);
}
\ No newline at end of file
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js
index b9433147a84..0ab6681bb8a 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -21,7 +21,6 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
//========================== On Load ================================================================
cur_frm.cscript.onload = function(doc, cdt, cdn) {
@@ -311,9 +310,7 @@ cur_frm.pformat.purchase_order_no = function(doc, cdt, cdn){
}
cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
- var args = {
- type: 'Purchase Receipt',
- doctype: 'Purchase Receipt'
+ if(cint(wn.boot.notification_settings.purchase_receipt)) {
+ cur_frm.email_doc(wn.boot.notification_settings.purchase_receipt);
}
- cur_frm.cscript.notify(doc, args);
}
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index 398a831d309..37b818e08c1 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -238,10 +238,12 @@ class TransactionBase:
return dcc
- def get_formatted_message(self, args):
- """ get formatted message for auto notification"""
- return get_obj('Notification Control').get_formatted_message(args)
-
+ def load_notification_message(self):
+ dt = self.doc.doctype.lower().replace(" ", "_")
+ if int(webnotes.conn.get_value("Notification Control", None, dt) or 0):
+ self.doc.fields["__notification_message"] = \
+ webnotes.conn.get_value("Notification Control", None, dt + "_message")
+
def add_communication_list(self):
# remove communications if present
self.doclist = webnotes.doclist(self.doclist).get({