From cbed64b4a80ec4be403ac86047ddece00b47a9ac Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 27 Jan 2012 13:06:28 +0530 Subject: [PATCH 1/9] fix to hide columns if empty content --- js/legacy/form.compressed.js | 3 ++- js/legacy/widgets/form/print_format.js | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 99eeaa1af0..6b496815b8 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -407,7 +407,8 @@ return layout;},print_std_add_table:function(t,layout,pf_list,dt,no_letterhead){
';for(var i=0;i Date: Fri, 27 Jan 2012 13:22:56 +0530 Subject: [PATCH 2/9] fix in print hide empty columns --- js/legacy/form.compressed.js | 4 ++-- js/legacy/widgets/form/print_format.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 6b496815b8..57b42349cf 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -407,8 +407,8 @@ return layout;},print_std_add_table:function(t,layout,pf_list,dt,no_letterhead){
';for(var i=0;i Date: Fri, 27 Jan 2012 13:43:57 +0530 Subject: [PATCH 3/9] print hide fix --- js/legacy/widgets/form/print_format.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/legacy/widgets/form/print_format.js b/js/legacy/widgets/form/print_format.js index c597c14cbc..91a065a704 100644 --- a/js/legacy/widgets/form/print_format.js +++ b/js/legacy/widgets/form/print_format.js @@ -645,7 +645,6 @@ print_table = function(dt, dn, fieldname, tabletype, cols, head_labels, widths, } for(var c=0; c Date: Fri, 27 Jan 2012 13:54:40 +0530 Subject: [PATCH 4/9] fixes to print hide --- js/legacy/form.compressed.js | 5 +++-- js/legacy/widgets/form/print_format.js | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 57b42349cf..4e54bef595 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -407,12 +407,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 Date: Fri, 27 Jan 2012 16:17:42 +0530 Subject: [PATCH 5/9] print format changes --- js/legacy/form.compressed.js | 4 ++-- js/legacy/widgets/form/print_format.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 4e54bef595..bc3a7183f7 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -407,8 +407,8 @@ return layout;},print_std_add_table:function(t,layout,pf_list,dt,no_letterhead){
';for(var i=0;i Date: Fri, 27 Jan 2012 17:21:33 +0530 Subject: [PATCH 6/9] print format - bypass printing table if table doesnt exist --- js/legacy/form.compressed.js | 2 +- js/legacy/widgets/form/print_format.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index bc3a7183f7..01abfe9109 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -407,7 +407,7 @@ return layout;},print_std_add_table:function(t,layout,pf_list,dt,no_letterhead){
';for(var i=0;i Date: Fri, 27 Jan 2012 18:47:55 +0530 Subject: [PATCH 7/9] Check support ticket settings while saving --- py/webnotes/utils/email_lib/receive.py | 2 +- py/webnotes/utils/email_lib/send.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) 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 b6c01d04df..7baba7c70f 100644 --- a/py/webnotes/utils/email_lib/send.py +++ b/py/webnotes/utils/email_lib/send.py @@ -194,7 +194,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) @@ -209,15 +223,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 # =========================================== From fe08e9c20e72bf2935b512e5643e92b3a8545fe7 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 30 Jan 2012 11:54:13 +0530 Subject: [PATCH 8/9] Fix: Search Field customization via customize form view --- py/webnotes/widgets/search.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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]: From 5c501cff25f304b90cbfa625fe4fc7e1f7cfd017 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 2 Feb 2012 11:40:25 +0530 Subject: [PATCH 9/9] roundNumber function, show cancelled in print format header, fixed load_from_db method of doclist --- js/legacy/form.compressed.js | 4 +-- js/legacy/utils/datatype.js | 9 +++++- js/legacy/widgets/autosuggest.js | 2 +- js/legacy/widgets/form/print_format.js | 18 ++++++++++++ js/legacy/wnf.compressed.js | 1 + py/webnotes/model/__init__.py | 39 ++++++++++++++++++++++++++ py/webnotes/model/doclist.py | 6 ++-- 7 files changed, 73 insertions(+), 6 deletions(-) diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 01abfe9109..5eb922b23e 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -346,7 +346,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.get_print_format',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.get_print_format',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='';} diff --git a/js/legacy/utils/datatype.js b/js/legacy/utils/datatype.js index 810d6549f1..4aa98d9a3a 100644 --- a/js/legacy/utils/datatype.js +++ b/js/legacy/utils/datatype.js @@ -318,4 +318,11 @@ function in_words(n) { } else { return bestguess; } -} \ No newline at end of file +} + + +function roundNumber(num, dec) { + var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); + return result; +} + diff --git a/js/legacy/widgets/autosuggest.js b/js/legacy/widgets/autosuggest.js index 29f7728bd8..0a22b26d6c 100644 --- a/js/legacy/widgets/autosuggest.js +++ b/js/legacy/widgets/autosuggest.js @@ -559,4 +559,4 @@ $ce = function ( type, attr, cont, html ) else if (t == "object") ne.appendChild( cont ); return ne; -}; \ No newline at end of file +}; diff --git a/js/legacy/widgets/form/print_format.js b/js/legacy/widgets/form/print_format.js index 3dc19bf4fa..104b50683e 100644 --- a/js/legacy/widgets/form/print_format.js +++ b/js/legacy/widgets/form/print_format.js @@ -151,6 +151,7 @@ $.extend(_p, { // if draft/archived, show draft/archived banner stat += _p.show_draft(args); stat += _p.show_archived(args); + stat += _p.show_cancelled(args); // Append args.body's content as a child of container container.innerHTML = args.body; @@ -219,6 +220,23 @@ $.extend(_p, { 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 ""; + } + }, + + + /* + Check if doc is cancelled + Display cancelled in header if true + */ + 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 ""; } diff --git a/js/legacy/wnf.compressed.js b/js/legacy/wnf.compressed.js index 96dcd9eabd..4ec778ddd4 100644 --- a/js/legacy/wnf.compressed.js +++ b/js/legacy/wnf.compressed.js @@ -63,6 +63,7 @@ remainder=n%1000000000}} if(remainder){if(remainder>=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;} var appVer=navigator.appVersion.toLowerCase();var is_minor=parseFloat(appVer);var is_major=parseInt(is_minor);var iePos=appVer.indexOf('msie');if(iePos!=-1){is_minor=parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos))) is_major=parseInt(is_minor);} var isIE=(iePos!=-1);var isIE6=(isIE&&is_major<=6);var isIE7=(isIE&&is_major>=7);if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){var isFF=1;var ffversion=new Number(RegExp.$1) diff --git a/py/webnotes/model/__init__.py b/py/webnotes/model/__init__.py index 2448f5d5be..3a7c9e5d5b 100644 --- a/py/webnotes/model/__init__.py +++ b/py/webnotes/model/__init__.py @@ -219,3 +219,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 3d679604bf..9839991034 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): """