diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
index c2b478e8e2..e7fb676bd0 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
@@ -443,3 +443,12 @@ cur_frm.cscript.convert_into_recurring_invoice = function(doc) {
refresh_field(['repeat_on_day_of_month', 'notification_email_address']);
}
}
+
+$import(Notification Control)
+cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
+ var args = {
+ type: 'Sales Invoice',
+ doctype: 'Receivable Voucher'
+ }
+ cur_frm.cscript.notify(doc, args);
+}
diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py
index 536bb6d8cc..af6225b03b 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py
@@ -570,9 +570,6 @@ class DocType(TransactionBase):
self.update_c_form()
- # on submit notification
- # get_obj('Notification Control').notify_contact('Sales Invoice', self.doc.doctype,self.doc.name, self.doc.email_id, self.doc.contact_person)
-
def update_c_form(self):
"""Update amended id in C-form"""
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index d3fa37b807..05fe049f9f 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -245,3 +245,12 @@ cur_frm.pformat.indent_no = function(doc, cdt, cdn){
return out;
}
+
+$import(Notification Control)
+cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
+ var args = {
+ type: 'Purchase Order',
+ doctype: 'Purchase Order'
+ }
+ cur_frm.cscript.notify(doc, args);
+}
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index 1a5d2d73e7..752e348d77 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -207,8 +207,6 @@ class DocType(TransactionBase):
self.doc.indent_no = '';
- # on submit notification
- get_obj('Notification Control').notify_contact('Purchase Order', self.doc.doctype,self.doc.name, self.doc.email_id, self.doc.contact_person)
# On Cancel
# -------------------------------------------------------------------------------------------------------
diff --git a/erpnext/hr/doctype/expense_voucher/expense_voucher.js b/erpnext/hr/doctype/expense_voucher/expense_voucher.js
index 7b34a4682d..bdad2c5267 100644
--- a/erpnext/hr/doctype/expense_voucher/expense_voucher.js
+++ b/erpnext/hr/doctype/expense_voucher/expense_voucher.js
@@ -84,6 +84,8 @@ cur_frm.cscript.sanctioned_amount = function(doc,cdt,cdn){
cur_frm.cscript.calculate_total(doc,cdt,cdn);
}
+$import(Notification Control);
+
cur_frm.cscript['Approve'] = function(doc,cdt,cdn){
if(user == doc.exp_approver){
@@ -120,6 +122,13 @@ cur_frm.cscript['Approve'] = function(doc,cdt,cdn){
refresh_field('approval_status');
hide_field(['Update Voucher', 'Approve', 'Reject', 'Calculate Total Amount']);
approve_voucher_dialog.hide();
+ var args = {
+ type: 'Expense Voucher Approved',
+ doctype: 'Expense Voucher',
+ contact_name: doc.employee_name,
+ send_to: doc.email_id
+ }
+ cur_frm.cscript.notify(doc, args);
}
else if(r.message == 'Incomplete'){
$i('approve_voucher_dialog_response').innerHTML = 'Incomplete Voucher';
@@ -181,6 +190,13 @@ cur_frm.cscript['Reject'] = function(doc,cdt,cdn){
refresh_field('approval_status');
hide_field(['Update Voucher', 'Approve', 'Reject', 'Calculate Total Amount']);
reject_voucher_dialog.hide();
+ var args = {
+ type: 'Expense Voucher Rejected',
+ doctype: 'Expense Voucher',
+ contact_name: doc.employee_name,
+ send_to: doc.email_id
+ }
+ cur_frm.cscript.notify(doc, args);
}
});
}
@@ -211,3 +227,12 @@ cur_frm.cscript['Update Voucher'] = function(doc){
cur_frm.refresh_header();
});
}
+
+$import(Notification Control)
+cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
+ var args = {
+ type: 'Expense Voucher',
+ doctype: 'Expense Voucher'
+ }
+ cur_frm.cscript.notify(doc, args);
+}
diff --git a/erpnext/hr/doctype/expense_voucher/expense_voucher.py b/erpnext/hr/doctype/expense_voucher/expense_voucher.py
index 01db068c2d..4352ccab56 100644
--- a/erpnext/hr/doctype/expense_voucher/expense_voucher.py
+++ b/erpnext/hr/doctype/expense_voucher/expense_voucher.py
@@ -72,7 +72,7 @@ class DocType:
set(self.doc, 'approval_status', 'Approved')
# on approval notification
- get_obj('Notification Control').notify_contact('Expense Voucher Approved', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name)
+ #get_obj('Notification Control').notify_contact('Expense Voucher Approved', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name)
return cstr('Approved')
@@ -83,7 +83,7 @@ class DocType:
set(self.doc, 'approval_status', 'Rejected')
# on approval notification
- get_obj('Notification Control').notify_contact('Expense Voucher Rejected', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name)
+ #get_obj('Notification Control').notify_contact('Expense Voucher Rejected', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name)
return cstr('Rejected')
@@ -140,4 +140,4 @@ class DocType:
set(self.doc, 'approval_status', 'Submitted')
def on_cancel(self):
- set(self.doc, 'approval_status', 'Cancelled')
\ No newline at end of file
+ set(self.doc, 'approval_status', 'Cancelled')
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 4c205a9f9d..9ff676f4a9 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -303,3 +303,12 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query=
else
return repl("SELECT name, item_name, description FROM tabItem WHERE `tabItem`.%(key)s LIKE '%s' %(cond)s ORDER BY tabItem.item_code DESC LIMIT 50", {cond:cond});
}
+
+$import(Notification Control)
+cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
+ var args = {
+ type: 'Quotation',
+ doctype: 'Quotation'
+ }
+ cur_frm.cscript.notify(doc, args);
+}
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 10bccaf79b..01e67eb5b6 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -25,9 +25,6 @@ class DocType(TransactionBase):
self.tname = 'Quotation Detail'
self.fname = 'quotation_details'
- # Notification objects
- self.notify_obj = get_obj('Notification Control')
-
# Autoname
# ---------
def autoname(self):
@@ -306,8 +303,6 @@ class DocType(TransactionBase):
#update enquiry status
self.update_enquiry('submit')
- # on submit notification
- self.notify_obj.notify_contact('Quotation', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.contact_person)
# ON CANCEL
# ==========================================================================
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 949abcd037..c7e9b82980 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -335,4 +335,11 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
}
-
+$import(Notification Control)
+cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
+ var args = {
+ type: 'Sales Order',
+ doctype: 'Sales Order'
+ }
+ cur_frm.cscript.notify(doc, args);
+}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 72245ebb94..aefe666940 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -366,10 +366,6 @@ class DocType(TransactionBase):
# set SO status
set(self.doc, 'status', 'Submitted')
- # on submit notification
- if self.doc.email_id:
- get_obj('Notification Control').notify_contact('Sales Order',self.doc.doctype,self.doc.name, self.doc.email_id, self.doc.contact_person)
-
# ON CANCEL
# ===============================================================================================
diff --git a/erpnext/setup/doctype/notification_control/notification_control.js b/erpnext/setup/doctype/notification_control/notification_control.js
index f18e38d76b..112395e2e1 100644
--- a/erpnext/setup/doctype/notification_control/notification_control.js
+++ b/erpnext/setup/doctype/notification_control/notification_control.js
@@ -7,4 +7,40 @@ cur_frm.cscript.select_transaction = function(doc, dt, dn) {
}
$c_obj('Notification Control','get_message',doc.select_transaction, callback)
}
-}
\ No newline at end of file
+}
+
+cur_frm.cscript.notify = function(doc, args) {
+ if(validate_email(args['send_to'] || doc.contact_email || '')) {
+ $c_obj('Notification Control', 'get_formatted_message', {
+ type: args['type'],
+ doctype: args['doctype'],
+ contact_name: args['contact_name'] || doc.contact_display
+ }, function(r, rt) {
+ if(!r.exc) {
+ var res = JSON.parse(r.message);
+ var send_from = (function() {
+ if(user!='Administrator') {
+ return user;
+ } else {
+ var cp = locals['Control Panel']['Control Panel'];
+ return (cp.auto_email_id || 'automail@erpnext.com');
+ }
+ })();
+ if(res.send) {
+ var print_heading = (doc.select_print_heading || args['type'])
+ sendmail(
+ args['send_to'] || doc.contact_email,
+ send_from,
+ send_from,
+ doc.company + " - " + print_heading,
+ res.message,
+ res.print_format
+ );
+ msgprint('This ' + print_heading + ' is being sent to '
+ + (args['send_to'] || doc.contact_email) + '
...');
+ }
+ }
+ //console.log(JSON.parse(r.message));
+ });
+ }
+}
diff --git a/erpnext/setup/doctype/notification_control/notification_control.py b/erpnext/setup/doctype/notification_control/notification_control.py
index 70d863db7d..216c46b180 100644
--- a/erpnext/setup/doctype/notification_control/notification_control.py
+++ b/erpnext/setup/doctype/notification_control/notification_control.py
@@ -3,27 +3,12 @@ import webnotes
from webnotes.utils import validate_email_add, cint, cstr
from webnotes.model.doc import Document
+from webnotes.model.code import get_obj
from webnotes import msgprint
sql = webnotes.conn.sql
# -----------------------------------------------------------------------------------------
-
-def get_formatted_message(head, body):
- if head:
- head = '
- %(body)s -
-