cleanup of notification control: now in boot

This commit is contained in:
Rushabh Mehta
2012-11-30 10:57:28 +05:30
parent e1e4aafd9b
commit 35c017a78f
23 changed files with 128 additions and 295 deletions

View File

@@ -22,45 +22,5 @@ cur_frm.cscript.select_transaction = function(doc, cdt, cdn) {
refresh_field('custom_message');
}
$c_obj(make_doclist(cdt, cdn),'get_message',doc.select_transaction, callback)
}
}
cur_frm.cscript.notify = function(doc, args) {
var doc = locals[doc.doctype][doc.name];
$c_obj(make_doclist(doc.doctype, doc.name), '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 {
return (wn.control_panel.auto_email_id ||
'ERPNext Notification<automail@erpnext.com>');
}
})();
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 <b>'
+ (args['send_to'] || doc.contact_email) + '</b><br />...');
} else {
msgprint('Invalid/Missing Email Address of Contact. Auto notification for '
+ print_heading + ' not sent.');
}
}
}
//console.log(JSON.parse(r.message));
});
}
}

View File

@@ -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 """\
<div>
%(salutation)s,
%(message)s
Thanks,
%(send_from)s
%(company)s
</div>""" % 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'