From 914ccc61d301f0287117661d2c823baf40d83df3 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 3 May 2012 11:48:43 +0530 Subject: [PATCH 1/4] grid recursive change bugfix --- js/all-app.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/js/all-app.js b/js/all-app.js index c35273ee9b..05b7938c55 100644 --- a/js/all-app.js +++ b/js/all-app.js @@ -839,7 +839,7 @@ if(this.txt){try{this.txt.focus();}catch(e){} this.txt.field_object=this;}} function DataField(){}DataField.prototype=new Field();DataField.prototype.make_input=function(){var me=this;this.input=$a_input(this.input_area,this.df.fieldtype=='Password'?'password':'text');this.get_value=function(){var v=this.input.value;if(this.validate) v=this.validate(v);return v;} -this.input.name=this.df.fieldname;$(this.input).change(function(){me.set_value($(this).val());});this.set_value=function(val){if(!me.last_value)me.last_value='';if(me.validate){val=me.validate(val);me.input.value=val;} +this.input.name=this.df.fieldname;$(this.input).change(function(){me.set_value(me.get_value&&me.get_value()||$(this.input).val());});this.set_value=function(val){if(!me.last_value)me.last_value='';if(me.validate){val=me.validate(val);me.input.value=val;} me.set(val);if(me.format_input) me.format_input();if(in_list(['Currency','Float','Int'],me.df.fieldtype)){if(flt(me.last_value)==flt(val)){me.last_value=val;return;}} me.last_value=val;me.run_trigger();} @@ -884,7 +884,7 @@ _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_n LinkField.prototype.set_input_value=function(val){var me=this;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;} if(cur_frm){if(val==locals[me.doctype][me.docname][me.df.fieldname]){me.run_trigger();return;}} me.set(val);if(_f.cur_grid_cell) -_f.cur_grid_cell.grid.cell_deselect();if(!val){me.run_trigger();return;} +_f.cur_grid_cell.grid.cell_deselect();if(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) fetch=cur_frm.fetch_dict[me.df.fieldname].columns.join(', ');$c('webnotes.widgets.form.utils.validate_link',{'value':val,'options':me.df.options,'fetch':fetch},function(r,rt){if(r.message=='Ok'){if($(me.txt).val()!=val){if((me.grid&&!from_selector)||(!me.grid)){$(me.txt).val(val);}} if(r.fetch_values) @@ -1042,6 +1042,13 @@ me.btn.set_working=me.set_working;me.btn.done_working=me.done_working;if(me.btn. wn.dom.css(me.btn,args.style);},set_working:function(){me.btn.disabled='disabled';if(me.btn.args.is_ajax){$(me.btn).css('margin-right','0px');} $(me.loading_img).css('display','inline');},done_working:function(){me.btn.disabled=false;if(me.btn.args.is_ajax){$(me.btn).css('margin-right','24px');} $(me.loading_img).toggle(false);}});this.make();} +/* + * lib/js/wn/ui/search.js + */ +wn.ui.Search=Class.extend({init:function(opts){$.extend(this,opts);var me=this;wn.model.with_doctype(this.doctype,function(r){me.make();me.dialog.show();});},make:function(){var me=this;this.dialog=new wn.ui.Dialog({title:this.doctype+' Search',width:500});this.list=new wn.ui.Listing({parent:$(this.dialog.body),appframe:this.dialog.appframe,new_doctype:this.doctype,doctype:this.doctype,method:'webnotes.widgets.doclistview.get',show_filters:true,style:'compact',get_args:function(){if(me.query){me.page_length=50;return{query:me.query}}else{return{doctype:me.doctype,fields:['`tab'+me.doctype+'`.name'],filters:me.list.filter_list.get_filters(),docstatus:['0','1']}}},render_row:function(parent,data){$ln=$('' ++data.name+'').appendTo(parent).click(function(){var val=$(this).attr('data-name');me.dialog.hide();if(me.callback) +me.callback(val);else +wn.set_route('Form',me.doctype,val);});}});this.list.filter_list.add_filter('name','like');this.list.run();}}) /* * lib/js/legacy/widgets/dialog.js */ @@ -1387,7 +1394,7 @@ wn.ui.toolbar.NewDialog=wn.ui.toolbar.SelectorDialog.extend({init:function(){thi /* * lib/js/wn/ui/toolbar/search.js */ -wn.ui.toolbar.Search=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._super({title:"Search",execute:function(val){selector.set_search(val);selector.show();},});this.set_values(wn.boot.profile.can_search.join(',').split(','));makeselector();}}); +wn.ui.toolbar.Search=wn.ui.toolbar.SelectorDialog.extend({init:function(){this._super({title:"Search",execute:function(val){new wn.ui.Search({doctype:val});},});this.set_values(wn.boot.profile.can_search.join(',').split(','));makeselector();}}); /* * lib/js/wn/ui/toolbar/report.js */ @@ -1523,7 +1530,7 @@ if(this.txt){try{this.txt.focus();}catch(e){} this.txt.field_object=this;}} function DataField(){}DataField.prototype=new Field();DataField.prototype.make_input=function(){var me=this;this.input=$a_input(this.input_area,this.df.fieldtype=='Password'?'password':'text');this.get_value=function(){var v=this.input.value;if(this.validate) v=this.validate(v);return v;} -this.input.name=this.df.fieldname;$(this.input).change(function(){me.set_value($(this).val());});this.set_value=function(val){if(!me.last_value)me.last_value='';if(me.validate){val=me.validate(val);me.input.value=val;} +this.input.name=this.df.fieldname;$(this.input).change(function(){me.set_value(me.get_value&&me.get_value()||$(this.input).val());});this.set_value=function(val){if(!me.last_value)me.last_value='';if(me.validate){val=me.validate(val);me.input.value=val;} me.set(val);if(me.format_input) me.format_input();if(in_list(['Currency','Float','Int'],me.df.fieldtype)){if(flt(me.last_value)==flt(val)){me.last_value=val;return;}} me.last_value=val;me.run_trigger();} @@ -1568,7 +1575,7 @@ _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_n LinkField.prototype.set_input_value=function(val){var me=this;var from_selector=false;if(selector&&selector.display)from_selector=true;me.refresh_label_icon();if(me.not_in_form){$(this.txt).val(val);return;} if(cur_frm){if(val==locals[me.doctype][me.docname][me.df.fieldname]){me.run_trigger();return;}} me.set(val);if(_f.cur_grid_cell) -_f.cur_grid_cell.grid.cell_deselect();if(!val){me.run_trigger();return;} +_f.cur_grid_cell.grid.cell_deselect();if(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) fetch=cur_frm.fetch_dict[me.df.fieldname].columns.join(', ');$c('webnotes.widgets.form.utils.validate_link',{'value':val,'options':me.df.options,'fetch':fetch},function(r,rt){if(r.message=='Ok'){if($(me.txt).val()!=val){if((me.grid&&!from_selector)||(!me.grid)){$(me.txt).val(val);}} if(r.fetch_values) @@ -1939,8 +1946,7 @@ return{}} _f.grid_date_cell='';_f.grid_refresh_date=function(){_f.grid_date_cell.grid.set_cell_value(_f.grid_date_cell);} _f.grid_refresh_field=function(temp,input){if($(input).val()!=_f.get_value(temp.doctype,temp.docname,temp.df.fieldname)) $(input).trigger('change');} -_f.Grid.prototype.remove_template=function(cell){var hc=this.head_row.cells[cell.cellIndex];if(!hc.template)return;if(!hc.template.activated)return;if(hc.template.df.fieldtype=='Date'){_f.grid_date_cell=cell;setTimeout('_f.grid_refresh_date()',100);}else{var input=hc.template.txt||hc.template.input;_f.grid_refresh_field(hc.template,input)} -if(hc.template&&hc.template.wrapper.parentNode) +_f.Grid.prototype.remove_template=function(cell){var hc=this.head_row.cells[cell.cellIndex];if(!hc.template)return;if(!hc.template.activated)return;if(hc.template&&hc.template.wrapper.parentNode) cell.div.removeChild(hc.template.wrapper);this.set_cell_value(cell);hc.template.activated=0;} _f.Grid.prototype.notify_keypress=function(e,keycode){if(keycode>=37&&keycode<=40&&e.shiftKey){if(text_dialog&&text_dialog.display){return;}}else return;if(!_f.cur_grid_cell)return;if(_f.cur_grid_cell.grid!=this)return;var ri=_f.cur_grid_cell.row.rowIndex;var ci=_f.cur_grid_cell.cellIndex;switch(keycode){case 38:if(ri>0){this.cell_select('',ri-1,ci);}break;case 40:if(ri<(this.tab.rows.length-1)){this.cell_select('',ri+1,ci);}break;case 39:if(ci<(this.head_row.cells.length-1)){this.cell_select('',ri,ci+1);}break;case 37:if(ci>1){this.cell_select('',ri,ci-1);}break;}} From e5982c0399e3dc90e08153682425aef1dfeb5148 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 12:37:26 +0530 Subject: [PATCH 2/4] email digest fixes --- .../doctype/email_digest/email_digest.py | 151 ++++++++++-------- 1 file changed, 83 insertions(+), 68 deletions(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index b3ea118cc6..ae3d800e3f 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -502,126 +502,141 @@ class DocType: body_dict = { 'invoiced_amount': { - 'table': 'invoiced_amount' in result and table({ - 'head': 'Invoiced Amount', - 'body': currency_amount_str \ - % (currency, fmt_money(result['invoiced_amount']['debit'])) - }), + 'table': result.get('invoiced_amount') and \ + table({ + 'head': 'Invoiced Amount', + 'body': currency_amount_str \ + % (currency, fmt_money(result['invoiced_amount'].get('debit'))) + }), 'idx': 300 }, 'payables': { - 'table': 'payables' in result and table({ - 'head': 'Payables', - 'body': currency_amount_str \ - % (currency, fmt_money(result['payables']['credit'])) - }), + 'table': result.get('payables') and \ + table({ + 'head': 'Payables', + 'body': currency_amount_str \ + % (currency, fmt_money(result['payables'].get('credit'))) + }), 'idx': 200 }, 'collections': { - 'table': 'collections' in result and table({ - 'head': 'Collections', - 'body': currency_amount_str \ - % (currency, fmt_money(result['collections']['credit'])) - }), + 'table': result.get('collections') and \ + table({ + 'head': 'Collections', + 'body': currency_amount_str \ + % (currency, fmt_money(result['collections'].get('credit'))) + }), 'idx': 301 }, 'payments': { - 'table': 'payments' in result and table({ - 'head': 'Payments', - 'body': currency_amount_str \ - % (currency, fmt_money(result['payments']['debit'])) - }), + 'table': result.get('payments') and \ + table({ + 'head': 'Payments', + 'body': currency_amount_str \ + % (currency, fmt_money(result['payments'].get('debit'))) + }), 'idx': 201 }, 'income': { - 'table': 'income' in result and table({ - 'head': 'Income', - 'body': currency_amount_str \ - % (currency, fmt_money(result['income']['value'])) - }), + 'table': result.get('income') and \ + table({ + 'head': 'Income', + 'body': currency_amount_str \ + % (currency, fmt_money(result['income'].get('value'))) + }), 'idx': 302 }, 'income_year_to_date': { - 'table': 'income_year_to_date' in result and table({ - 'head': 'Income Year To Date', - 'body': currency_amount_str \ - % (currency, fmt_money(result['income_year_to_date']['value'])) - }), + 'table': result.get('income_year_to_date') and \ + table({ + 'head': 'Income Year To Date', + 'body': currency_amount_str \ + % (currency, fmt_money(result['income_year_to_date'].get('value'))) + }), 'idx': 303 }, 'expenses_booked': { - 'table': 'expenses_booked' in result and table({ - 'head': 'Expenses Booked', - 'body': currency_amount_str \ - % (currency, fmt_money(result['expenses_booked']['value'])) - }), + 'table': result.get('expenses_booked') and \ + table({ + 'head': 'Expenses Booked', + 'body': currency_amount_str \ + % (currency, fmt_money(result['expenses_booked'].get('value'))) + }), 'idx': 202 }, 'bank_balance': { - 'table': 'bank_balance' in result and result['bank_balance'] and table({ - 'head': 'Bank Balance', - 'body': [ - [ - "%s" % bank['name'], - currency_amount_str % (currency, fmt_money(bank['value'])) - ] for bank in result.get('bank_balance', []) - ] - }), + 'table': result.get('bank_balance') and \ + table({ + 'head': 'Bank Balance', + 'body': [ + [ + "%s" \ + % bank['name'], + currency_amount_str % (currency, fmt_money(bank.get('value'))) + ] for bank in result['bank_balance'] + ] + }), 'idx': 400 }, 'new_leads': { - 'table': 'new_leads' in result and table({ - 'head': 'New Leads', - 'body': '%s' % result['new_leads']['count'] - }), + 'table': result.get('new_leads') and \ + table({ + 'head': 'New Leads', + 'body': '%s' % result['new_leads'].get('count') + }), 'idx': 100 }, 'new_enquiries': { - 'table': 'new_enquiries' in result and table({ - 'head': 'New Enquiries', - 'body': '%s' % result['new_enquiries']['count'] - }), + 'table': result.get('new_enquiries') and \ + table({ + 'head': 'New Enquiries', + 'body': '%s' % result['new_enquiries'].get('count') + }), 'idx': 101 }, 'new_quotations': { - 'table': 'new_quotations' in result and table({ - 'head': 'New Quotations', - 'body': '%s' % result['new_quotations']['count'] - }), + 'table': result.get('new_quotations') and \ + table({ + 'head': 'New Quotations', + 'body': '%s' % result['new_quotations'].get('count') + }), 'idx': 102 }, 'new_sales_orders': { - 'table': 'new_sales_orders' in result and table({ - 'head': 'New Sales Orders', - 'body': '%s' % result['new_sales_orders']['count'] - }), + 'table': result.get('new_sales_orders') and \ + table({ + 'head': 'New Sales Orders', + 'body': '%s' % result['new_sales_orders'].get('count') + }), 'idx': 103 }, 'new_purchase_orders': { - 'table': 'new_purchase_orders' in result and table({ - 'head': 'New Purchase Orders', - 'body': '%s' % result['new_purchase_orders']['count'] - }), + 'table': result.get('new_purchase_orders') and \ + table({ + 'head': 'New Purchase Orders', + 'body': '%s' % result['new_purchase_orders'].get('count') + }), 'idx': 104 }, 'new_transactions': { - 'table': 'new_transactions' in result and table({ - 'head': 'New Transactions', - 'body': '%s' % result['new_transactions']['count'] - }), + 'table': result.get('new_transactions') and \ + table({ + 'head': 'New Transactions', + 'body': '%s' % result['new_transactions'].get('count') + }), 'idx': 105 } From 996abdd155dd71de16af376be8ba24cfd82e42cb Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 12:48:44 +0530 Subject: [PATCH 3/4] fix in email digest --- erpnext/setup/doctype/email_digest/email_digest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index ae3d800e3f..40472a27cb 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -142,7 +142,7 @@ class DocType: r['value'] = float(r['debit'] - r['credit']) #webnotes.msgprint(query) #webnotes.msgprint(res) - result[query] = (res and len(res)==1) and res[0] or (res and res or None) + result[query] = res and (len(res)==1 and res[0]) or (res or None) if result[query] is None: del result[query] From 57bc3f424fdc8d462187a74265044293405e29d2 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 3 May 2012 12:57:56 +0530 Subject: [PATCH 4/4] fix in email digest --- erpnext/setup/doctype/email_digest/email_digest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index 40472a27cb..351d6722b9 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -580,7 +580,9 @@ class DocType: "%s" \ % bank['name'], currency_amount_str % (currency, fmt_money(bank.get('value'))) - ] for bank in result['bank_balance'] + ] for bank in (isinstance(result['bank_balance'], list) and \ + result['bank_balance'] or \ + [result['bank_balance']]) ] }), 'idx': 400