diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 8d65fa12e5..f5e9e51129 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -366,7 +366,7 @@ $.extend(_p,{show_dialog:function(){if(!_p.dialog){_p.make_dialog();} _p.dialog.show();},make_dialog:function(){var d=new Dialog(360,140,'Print Formats',[['HTML','Select'],['Check','No Letterhead'],['HTML','Buttons']]);$btn(d.widgets.Buttons,'Print',function(){_p.build(sel_val(cur_frm.print_sel),_p.go,d.widgets['No Letterhead'].checked);},{cssFloat:'right',marginBottom:'16px',marginLeft:'7px'},'green');$btn(d.widgets.Buttons,'Preview',function(){_p.build(sel_val(cur_frm.print_sel),_p.preview,d.widgets['No Letterhead'].checked);},{cssFloat:'right',marginBottom:'16px'},'');d.onshow=function(){var c=_p.dialog.widgets['Select'];if(c.cur_sel&&c.cur_sel.parentNode==c){c.removeChild(c.cur_sel);} c.appendChild(cur_frm.print_sel);c.cur_sel=cur_frm.print_sel;} _p.dialog=d;},formats:{},build:function(fmtname,onload,no_letterhead,only_body){args={fmtname:fmtname,onload:onload,no_letterhead:no_letterhead,only_body:only_body};if(!cur_frm){alert('No Document Selected');return;} -var doc=locals[cur_frm.doctype][cur_frm.docname];if(args.fmtname=='Standard'){args.onload(_p.render({body:_p.print_std(args.no_letterhead),style:_p.print_style,doc:doc,title:doc.name,no_letterhead:args.no_letterhead,only_body:args.only_body}));}else{if(!_p.formats[args.fmtname]){var build_args=args;$c(command='webnotes.widgets.form.print_format.get',args={'name':build_args.fmtname},fn=function(r,rt){_p.formats[build_args.fmtname]=r.message;build_args.onload(_p.render({body:_p.formats[build_args.fmtname],style:'',doc:doc,title:doc.name,no_letterhead:build_args.no_letterhead,only_body:build_args.only_body}));});}else{args.onload(_p.render({body:_p.formats[args.fmtname],style:'',doc:doc,title:doc.name,no_letterhead:args.no_letterhead,only_body:args.only_body}));}}},render:function(args){var container=document.createElement('div');var stat='';stat+=_p.show_draft(args);stat+=_p.show_archived(args);container.innerHTML=args.body;_p.show_letterhead(container,args);_p.run_embedded_js(container,args.doc);var style=_p.consolidate_css(container,args);_p.render_header_on_break(container,args);return _p.render_final(style,stat,container,args);},head_banner_format:function(){return"\ +var doc=locals[cur_frm.doctype][cur_frm.docname];if(args.fmtname=='Standard'){args.onload(_p.render({body:_p.print_std(args.no_letterhead),style:_p.print_style,doc:doc,title:doc.name,no_letterhead:args.no_letterhead,only_body:args.only_body}));}else{if(!_p.formats[args.fmtname]){var build_args=args;$c(command='webnotes.widgets.form.print_format.get',args={'name':build_args.fmtname},fn=function(r,rt){_p.formats[build_args.fmtname]=r.message;build_args.onload(_p.render({body:_p.formats[build_args.fmtname],style:'',doc:doc,title:doc.name,no_letterhead:build_args.no_letterhead,only_body:build_args.only_body}));});}else{args.onload(_p.render({body:_p.formats[args.fmtname],style:'',doc:doc,title:doc.name,no_letterhead:args.no_letterhead,only_body:args.only_body}));}}},render:function(args){var container=document.createElement('div');var stat='';stat+=_p.show_draft(args);stat+=_p.show_archived(args);stat+=_p.show_cancelled(args);container.innerHTML=args.body;_p.show_letterhead(container,args);_p.run_embedded_js(container,args.doc);var style=_p.consolidate_css(container,args);_p.render_header_on_break(container,args);return _p.render_final(style,stat,container,args);},head_banner_format:function(){return"\
\ {{DESCRIPTION}}\
"},show_draft:function(args){var is_doctype_submittable=0;var plist=locals['DocPerm'];for(var perm in plist){var p=plist[perm];if((p.parent==args.doc.doctype)&&(p.submit==1)){is_doctype_submittable=1;break;}} -if(args.doc&&cint(args.doc.docstatus)==0&&is_doctype_submittable){draft=_p.head_banner_format();draft=draft.replace("{{HEAD}}","DRAFT");draft=draft.replace("{{DESCRIPTION}}","This box will go away after the document is submitted.");return draft;}else{return"";}},show_archived:function(args){if(args.doc&&args.doc.__archived){archived=_p.head_banner_format();archived=archived.replace("{{HEAD}}","ARCHIVED");archived=archived.replace("{{DESCRIPTION}}","You must restore this document to make it editable.");}else{return"";}},consolidate_css:function(container,args){var body_style='';var style_list=container.getElementsByTagName('style');while(style_list&&style_list.length>0){for(i in style_list){if(style_list[i]&&style_list[i].innerHTML){body_style+=style_list[i].innerHTML;var parent=style_list[i].parentNode;if(parent){parent.removeChild(style_list[i]);}else{container.removeChild(style_list[i]);}}} +if(args.doc&&cint(args.doc.docstatus)==0&&is_doctype_submittable){draft=_p.head_banner_format();draft=draft.replace("{{HEAD}}","DRAFT");draft=draft.replace("{{DESCRIPTION}}","This box will go away after the document is submitted.");return draft;}else{return"";}},show_archived:function(args){if(args.doc&&args.doc.__archived){archived=_p.head_banner_format();archived=archived.replace("{{HEAD}}","ARCHIVED");archived=archived.replace("{{DESCRIPTION}}","You must restore this document to make it editable.");return archived;}else{return"";}},show_cancelled:function(args){if(args.doc&&args.doc.docstatus==2){cancelled=_p.head_banner_format();cancelled=cancelled.replace("{{HEAD}}","CANCELLED");cancelled=cancelled.replace("{{DESCRIPTION}}","You must amend this document to make it editable.");return cancelled;}else{return"";}},consolidate_css:function(container,args){var body_style='';var style_list=container.getElementsByTagName('style');while(style_list&&style_list.length>0){for(i in style_list){if(style_list[i]&&style_list[i].innerHTML){body_style+=style_list[i].innerHTML;var parent=style_list[i].parentNode;if(parent){parent.removeChild(style_list[i]);}else{container.removeChild(style_list[i]);}}} style_list=container.getElementsByTagName('style');} style_concat=(args.only_body?'':_p.def_print_style_body) +_p.def_print_style_other+args.style+body_style;return style_concat;},run_embedded_js:function(container,doc){var jslist=container.getElementsByTagName('script');while(jslist&&jslist.length>0){for(i in jslist){if(jslist[i]&&jslist[i].innerHTML){var code=jslist[i].innerHTML;var parent=jslist[i].parentNode;var span=$a(parent,'span');parent.replaceChild(span,jslist[i]);var val=code?eval(code):'';if(!val||typeof(val)=='object'){val='';} @@ -427,11 +427,13 @@ return layout;},print_std_add_table:function(t,layout,pf_list,dt,no_letterhead){
';for(var i=0;iSR';$y(cell,{width:'30px'});$y(cell,me.head_cell_style);col_start++;} for(var c=col_start;c=100)comma=',' else comma='' return bestguess+comma+' '+in_words(remainder);}else{return bestguess;}} +function roundNumber(num,dec){var result=Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);return result;} /* * lib/js/legacy/utils/browser_detect.js */ diff --git a/py/webnotes/model/__init__.py b/py/webnotes/model/__init__.py index bcbd76e923..38f9e8b608 100644 --- a/py/webnotes/model/__init__.py +++ b/py/webnotes/model/__init__.py @@ -204,3 +204,42 @@ def copytables(srctype, src, srcfield, tartype, tar, tarfield, srcfields, tarfie def db_exists(dt, dn): import webnotes return webnotes.conn.exists(dt, dn) + + +def delete_fields(args_dict, delete=0): + """ + Delete a field. + * Deletes record from `tabDocField` + * If not single doctype: Drops column from table + * If single, deletes record from `tabSingles` + + args_dict = { dt: [field names] } + """ + for dt in args_dict.keys(): + fields = args_dict[dt] + if not fields: continue + + webnotes.conn.sql("""\ + DELETE FROM `tabDocField` + WHERE parent=%s AND fieldname IN (%s) + """ % ('%s', ", ".join(['"' + f + '"' for f in fields])), dt) + + # Delete the data / column only if delete is specified + if not delete: continue + + is_single = webnotes.conn.sql("select issingle from tabDocType where name = '%s'" % dt) + is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0 + if is_single: + webnotes.conn.sql("""\ + DELETE FROM `tabSingles` + WHERE doctype=%s AND field IN (%s) + """ % ('%s', ", ".join(['"' + f + '"' for f in fields])), dt) + else: + existing_fields = webnotes.conn.sql("desc `tab%s`" % dt) + existing_fields = existing_fields and [e[0] for e in existing_fields] or [] + query = "ALTER TABLE `tab%s` " % dt + \ + ", ".join(["DROP COLUMN `%s`" % f for f in fields if f in existing_fields]) + webnotes.conn.commit() + webnotes.conn.sql(query) + + diff --git a/py/webnotes/model/doclist.py b/py/webnotes/model/doclist.py index e16cafd8c7..9334c5c38e 100644 --- a/py/webnotes/model/doclist.py +++ b/py/webnotes/model/doclist.py @@ -19,7 +19,7 @@ class DocList: if dt and dn: self.load_from_db(dt, dn) - def load_from_db(self, dt, dn): + def load_from_db(self, dt, dn, prefix='tab'): """ Load doclist from dt """ @@ -35,7 +35,9 @@ class DocList: for t in tablefields: doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix) - self.docs = docs + self.docs = doclist + self.doc = doc + self.children = doclist[1:] def __iter__(self): """ diff --git a/py/webnotes/utils/email_lib/receive.py b/py/webnotes/utils/email_lib/receive.py index 094b483495..ab2631e43c 100644 --- a/py/webnotes/utils/email_lib/receive.py +++ b/py/webnotes/utils/email_lib/receive.py @@ -97,7 +97,7 @@ class POP3Mailbox: def __init__(self, settings_doc): """ settings_doc must contain - is_ssl, host, username, password + use_ssl, host, username, password (by name or object) """ if type(settings_doc)==str: diff --git a/py/webnotes/utils/email_lib/send.py b/py/webnotes/utils/email_lib/send.py index f7d72daa41..25fd1370aa 100644 --- a/py/webnotes/utils/email_lib/send.py +++ b/py/webnotes/utils/email_lib/send.py @@ -195,7 +195,21 @@ class EMail: if (not send_now) and getattr(webnotes.defs, 'batch_emails', 0): self.add_to_queue() return + + sess = self.smtp_connect() + + sess.sendmail(self.sender, self.recipients, self.msg_root.as_string()) + + try: + sess.quit() + except: + pass + + def smtp_connect(self): + """ + Gets a smtp connection + """ import smtplib sess = smtplib.SMTP(self.server, self.port or None) @@ -210,15 +224,8 @@ class EMail: if ret[0]!=235: msgprint(ret[1]) raise Exception - - sess.sendmail(self.sender, self.recipients, self.msg_root.as_string()) - - try: - sess.quit() - except: - pass - + return sess # =========================================== diff --git a/py/webnotes/widgets/search.py b/py/webnotes/widgets/search.py index bfd1c08486..5b1e4f6d7e 100644 --- a/py/webnotes/widgets/search.py +++ b/py/webnotes/widgets/search.py @@ -3,8 +3,12 @@ import webnotes # this is called when a new doctype is setup for search - to set the filters def getsearchfields(): - - sf = webnotes.conn.sql("select search_fields from tabDocType where name=%s", webnotes.form.getvalue("doctype")) + sf = webnotes.conn.sql("""\ + SELECT value FROM `tabProperty Setter` + WHERE doc_type=%s AND doc_name=%s AND property='search_fields'""", \ + (webnotes.form.getvalue("doctype"), webnotes.form.getvalue("doctype"))) + if not (sf and len(sf)>0 and sf[0][0]): + sf = webnotes.conn.sql("select search_fields from tabDocType where name=%s", webnotes.form.getvalue("doctype")) sf = sf and sf[0][0] or '' sf = [s.strip() for s in sf.split(',')] if sf and sf[0]: