From 8eadf09e991e632197f9dd9da8319cc5eb78f16e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sun, 17 Jun 2012 21:48:33 +0530 Subject: [PATCH 01/14] recurring invoice : quarterly, half-yearly and yearly --- .../accounts/doctype/gl_control/gl_control.py | 21 ++++++++++++------- .../doctype/sales_invoice/sales_invoice.py | 9 +++++--- .../doctype/sales_invoice/sales_invoice.txt | 19 +++++++++++++++-- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/gl_control/gl_control.py b/erpnext/accounts/doctype/gl_control/gl_control.py index 2f84a9c7f4..66a0d65b74 100644 --- a/erpnext/accounts/doctype/gl_control/gl_control.py +++ b/erpnext/accounts/doctype/gl_control/gl_control.py @@ -484,11 +484,13 @@ def manage_recurring_invoices(): Create recurring invoices on specific date by copying the original one and notify the concerned people """ - rv = webnotes.conn.sql("""select name, recurring_id from `tabSales Invoice` where ifnull(convert_into_recurring_invoice, 0) = 1 - and next_date = %s and next_date <= ifnull(end_date, '2199-12-31') and docstatus=1""", nowdate()) + rv = webnotes.conn.sql("""select name, recurring_id from `tabSales Invoice` \ + where ifnull(convert_into_recurring_invoice, 0) = 1 and next_date = %s \ + and next_date <= ifnull(end_date, '2199-12-31') and docstatus=1""", nowdate()) for d in rv: - if not webnotes.conn.sql("""select name from `tabSales Invoice` where posting_date = %s and recurring_id = %s and docstatus=1""", (nowdate(), d[1])): + if not webnotes.conn.sql("""select name from `tabSales Invoice` \ + where posting_date = %s and recurring_id = %s and docstatus=1""", (nowdate(), d[1])): prev_rv = get_obj('Sales Invoice', d[0], with_children=1) new_rv = create_new_invoice(prev_rv) @@ -499,13 +501,16 @@ def create_new_invoice(prev_rv): # clone rv new_rv = clone(prev_rv) + mdict = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} + mcount = mdict[prev_rv.doc.recurring_type] + # update new rv new_rv.doc.posting_date = new_rv.doc.next_date new_rv.doc.aging_date = new_rv.doc.next_date new_rv.doc.due_date = add_days(new_rv.doc.next_date, cint(date_diff(prev_rv.doc.due_date, prev_rv.doc.posting_date))) - new_rv.doc.invoice_period_from_date = get_next_month_date(new_rv.doc.invoice_period_from_date) - new_rv.doc.invoice_period_to_date = get_next_month_date(new_rv.doc.invoice_period_to_date) + new_rv.doc.invoice_period_from_date = get_next_date(new_rv.doc.invoice_period_from_date, mcount) + new_rv.doc.invoice_period_to_date = get_next_date(new_rv.doc.invoice_period_to_date, mcount) new_rv.doc.owner = prev_rv.doc.owner new_rv.doc.save() @@ -515,13 +520,13 @@ def create_new_invoice(prev_rv): return new_rv -def get_next_month_date(dt): +def get_next_date(dt, mcount): import datetime - m = getdate(dt).month + 1 + m = getdate(dt).month + mcount y = getdate(dt).year d = getdate(dt).day if m > 12: - m, y = 1, y+1 + m, y = m-12, y+1 try: next_month_date = datetime.date(y, m, d) except: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 7b62684db9..f07c7b3ffc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -686,7 +686,9 @@ class DocType(TransactionBase): def convert_into_recurring(self): if self.doc.convert_into_recurring_invoice: - if not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date: + if not self.doc.recurring_type: + msgprint("Please select recurring type", raise_exception=1) + elif not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date: msgprint("Invoice period from date and to date is mandatory for recurring invoice", raise_exception=1) self.set_next_date() if not self.doc.recurring_id: @@ -702,10 +704,11 @@ class DocType(TransactionBase): will be generated e.g. 05, 28 etc.""", raise_exception=1) import datetime - m = getdate(self.doc.posting_date).month + 1 + mcount = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12} + m = getdate(self.doc.posting_date).month + mcount[self.doc.recurring_type] y = getdate(self.doc.posting_date).year if m > 12: - m, y = 1, y+1 + m, y = m-12, y+1 try: next_date = datetime.date(y, m, cint(self.doc.repeat_on_day_of_month)) except: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt index d2439c8113..94699413a6 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt @@ -3,9 +3,9 @@ # These values are common in all dictionaries { - 'creation': '2012-04-13 11:56:18', + 'creation': '2012-06-11 12:09:54', 'docstatus': 0, - 'modified': '2012-06-04 14:40:59', + 'modified': '2012-06-17 21:37:36', 'modified_by': u'Administrator', 'owner': u'Administrator' }, @@ -1480,6 +1480,21 @@ 'trigger': u'Client' }, + # DocField + { + 'allow_on_submit': 1, + 'depends_on': u'eval:doc.convert_into_recurring_invoice==1', + 'description': u'Select the period when the invoice will be generated automatically', + 'doctype': u'DocField', + 'fieldname': u'recurring_type', + 'fieldtype': u'Select', + 'label': u'Recurring Type', + 'no_copy': 1, + 'options': u'Monthly\nQuarterly\nHalf-yearly\nYearly', + 'permlevel': 0, + 'print_hide': 1 + }, + # DocField { 'allow_on_submit': 1, From 3ad3ebdaec39a7931645fc4bf615484670387cdd Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sun, 17 Jun 2012 21:54:50 +0530 Subject: [PATCH 02/14] set recurring type as Monthly in all old sales invoice --- erpnext/patches/june_2012/set_recurring_type.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 erpnext/patches/june_2012/set_recurring_type.py diff --git a/erpnext/patches/june_2012/set_recurring_type.py b/erpnext/patches/june_2012/set_recurring_type.py new file mode 100644 index 0000000000..1164b67773 --- /dev/null +++ b/erpnext/patches/june_2012/set_recurring_type.py @@ -0,0 +1,6 @@ +def execute(): + import webnotes + from webnotes.modules import reload_doc + reload_doc('accounts', 'doctype', 'sales_invoice') + + webnotes.conn.sql("update `tabSales Invoice` set recurring_type = 'Monthly' where ifnull(convert_into_recurring_invoice, 0) = 1") \ No newline at end of file From 3adfa9595edc27c19be3e64b39f620fb3735f512 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sun, 17 Jun 2012 21:57:37 +0530 Subject: [PATCH 03/14] patch list updated --- erpnext/patches/patch_list.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py index 98c3aff772..fd734a9a6c 100644 --- a/erpnext/patches/patch_list.py +++ b/erpnext/patches/patch_list.py @@ -442,4 +442,9 @@ patch_list = [ 'patch_file': 'series_unique_patch', 'description': "add unique constraint to series table's name column" }, + { + 'patch_module': 'patches.june_2012', + 'patch_file': 'set_recurring_type', + 'description': "set recurring type as monthly in old" + }, ] \ No newline at end of file From 28447e84c2a7ffd002cd078c23324983444f5a81 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 18 Jun 2012 11:03:51 +0530 Subject: [PATCH 04/14] Update master --- erpnext/accounts/doctype/sales_invoice/sales_invoice.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt index 94699413a6..969a7dc6d7 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt @@ -5,7 +5,7 @@ { 'creation': '2012-06-11 12:09:54', 'docstatus': 0, - 'modified': '2012-06-17 21:37:36', + 'modified': '2012-06-17 21:37:40', 'modified_by': u'Administrator', 'owner': u'Administrator' }, From 34b4d26c1a8d40e854913886224359ce08394b19 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 18 Jun 2012 11:18:27 +0530 Subject: [PATCH 05/14] reload_doc replaced with sync in patch --- erpnext/patches/june_2012/set_recurring_type.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/june_2012/set_recurring_type.py b/erpnext/patches/june_2012/set_recurring_type.py index 1164b67773..bfb925c6b8 100644 --- a/erpnext/patches/june_2012/set_recurring_type.py +++ b/erpnext/patches/june_2012/set_recurring_type.py @@ -1,6 +1,6 @@ def execute(): import webnotes - from webnotes.modules import reload_doc - reload_doc('accounts', 'doctype', 'sales_invoice') + from webnotes.model.sync import sync + sync('accounts', 'sales_invoice') webnotes.conn.sql("update `tabSales Invoice` set recurring_type = 'Monthly' where ifnull(convert_into_recurring_invoice, 0) = 1") \ No newline at end of file From 785fe9abc4337fd6f0020f2fe84c07bab90e762d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 18 Jun 2012 12:43:25 +0530 Subject: [PATCH 06/14] validation changed in supplier --- erpnext/buying/doctype/supplier/supplier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 524e03d78e..67a2aae44f 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -108,7 +108,7 @@ class DocType: msgprint("Supplier Type is mandatory") raise Exception - if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)): + if not sql("select name from tabAccount where name=%s and debit_or_credit = 'Credit' and ifnull(is_pl_account, 'No') = 'No'", (self.doc.supplier_type + " - " + abbr)): # if not group created , create it self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr) From 38192029e9abec9d2c5c0e325a53fa7ab8929c17 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 18 Jun 2012 15:05:20 +0530 Subject: [PATCH 07/14] SetTimeout hack - in link fields if data is typed and not selected from autocomplete, run validations and triggers --- public/js/all-app.js | 20 ++++++++++++-------- public/js/fields.js | 10 ++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/public/js/all-app.js b/public/js/all-app.js index 32a2e2965b..298840eb97 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -734,19 +734,21 @@ return v;};function LinkField(){}LinkField.prototype=new Field();LinkField.proto $(me.btn2).css('display','inline-block');else $dh(me.btn2);}} me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;} me.get_value=function(){return me.txt.value;} -$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display) -return;me.set_input_value('');}})} +$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(me.txt).change(function(event){me.wait=false;var val=me.get_value();if(!val){if(selector&&selector.display) +return;me.set_input_value('');} +setTimeout(function(){if(!me.wait){me.validate_link(val);}},100);});} LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm) var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}} LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);} if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}} me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}} _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}} -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;} +LinkField.prototype.set_input_value=function(val){var me=this;me.wait=true;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(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} -var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) +me.validate_link(val);} +LinkField.prototype.validate_link=function(val){var me=this;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) me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('

    Click here to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)}) @@ -1557,19 +1559,21 @@ return v;};function LinkField(){}LinkField.prototype=new Field();LinkField.proto $(me.btn2).css('display','inline-block');else $dh(me.btn2);}} me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;} me.get_value=function(){return me.txt.value;} -$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display) -return;me.set_input_value('');}})} +$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(me.txt).change(function(event){me.wait=false;var val=me.get_value();if(!val){if(selector&&selector.display) +return;me.set_input_value('');} +setTimeout(function(){if(!me.wait){me.validate_link(val);}},100);});} LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm) var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}} LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);} if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}} me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}} _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}} -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;} +LinkField.prototype.set_input_value=function(val){var me=this;me.wait=true;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(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} -var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) +me.validate_link(val);} +LinkField.prototype.validate_link=function(val){var me=this;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) me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('

    Click here to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)}) diff --git a/public/js/fields.js b/public/js/fields.js index dba9e5c249..b23e04bd8f 100644 --- a/public/js/fields.js +++ b/public/js/fields.js @@ -98,19 +98,21 @@ return v;};function LinkField(){}LinkField.prototype=new Field();LinkField.proto $(me.btn2).css('display','inline-block');else $dh(me.btn2);}} me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;} me.get_value=function(){return me.txt.value;} -$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display) -return;me.set_input_value('');}})} +$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(me.txt).change(function(event){me.wait=false;var val=me.get_value();if(!val){if(selector&&selector.display) +return;me.set_input_value('');} +setTimeout(function(){if(!me.wait){me.validate_link(val);}},100);});} LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm) var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}} LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);} if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}} me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}} _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}} -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;} +LinkField.prototype.set_input_value=function(val){var me=this;me.wait=true;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(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} -var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) +me.validate_link(val);} +LinkField.prototype.validate_link=function(val){var me=this;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) me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('

    Click here to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)}) From 422a27cde0711212d689c3767e08d41709ecb79b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 18 Jun 2012 17:37:04 +0530 Subject: [PATCH 08/14] fix in web page saving issue --- erpnext/website/doctype/web_page/web_page.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/website/doctype/web_page/web_page.py b/erpnext/website/doctype/web_page/web_page.py index b03e42495a..27ce5c053e 100644 --- a/erpnext/website/doctype/web_page/web_page.py +++ b/erpnext/website/doctype/web_page/web_page.py @@ -25,7 +25,7 @@ class DocType: """name from title""" self.doc.name = website.utils.page_name(self.doc.title) - def validate(self): + def on_update(self): """make page for this product""" from jinja2 import Template from webnotes.utils import global_date_format @@ -62,6 +62,9 @@ class DocType: website.utils.add_guest_access_to_page(p.name) self.cleanup_temp() + + self.doc.save() + self.if_home_clear_cache() def add_page_links(self): From f8946b1e31c59038fb059d8c3f78d8b600844a71 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 18 Jun 2012 18:04:28 +0530 Subject: [PATCH 09/14] fix in buttons displayed - on change of status in lead form --- erpnext/selling/doctype/lead/lead.js | 21 +++++++++++++++------ public/js/all-app.js | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js index 5d434495c0..389dce0db1 100644 --- a/erpnext/selling/doctype/lead/lead.js +++ b/erpnext/selling/doctype/lead/lead.js @@ -45,15 +45,24 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.cscript.make_communication_body(); } +cur_frm.cscript.refresh_custom_buttons = function() { + cur_frm.clear_custom_buttons(); + if(!doc.__islocal && !in_list(['Converted', 'Lead Lost'], doc.status)) { + if (doc.source != 'Existing Customer') { + cur_frm.add_custom_button('Create Customer', + cur_frm.cscript['Create Customer']); + } + cur_frm.add_custom_button('Create Opportunity', + cur_frm.cscript['Create Opportunity']); + cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); + } +} + cur_frm.cscript.refresh = function(doc, cdt, cdn) { // custom buttons //--------------- - cur_frm.clear_custom_buttons() - if(!doc.__islocal && !in_list(['Converted', 'Lead Lost'], doc.status)) { - if (doc.source != 'Existing Customer') cur_frm.add_custom_button('Create Customer', cur_frm.cscript['Create Customer']); - cur_frm.add_custom_button('Create Opportunity', cur_frm.cscript['Create Opportunity']); - cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); - } + cur_frm.cscript.refresh_custom_buttons(); + erpnext.hide_naming_series(); if (!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn); diff --git a/public/js/all-app.js b/public/js/all-app.js index 298840eb97..ec43c7013d 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -1748,7 +1748,7 @@ continue;var fn=f.fieldname?f.fieldname:f.label;var fld=make_field(f,this.doctyp if(f.fieldtype=='Section Break'){sec=fld;this.sections.push(fld);} if((f.fieldtype=='Section Break')&&(fl[i+1])&&(fl[i+1].fieldtype!='Column Break')&&!f.hidden){var c=this.layout.addcell();$y(c.wrapper,{padding:'8px'});}}} _f.Frm.prototype.add_custom_button=function(label,fn,icon){this.frm_head.appframe.add_button(label,fn,icon);} -_f.Frm.prototype.clear_custom_buttons=function(){} +_f.Frm.prototype.clear_custom_buttons=function(){this.frm_head.refresh_toolbar()} _f.Frm.prototype.add_fetch=function(link_field,src_field,tar_field){if(!this.fetch_dict[link_field]){this.fetch_dict[link_field]={'columns':[],'fields':[]}} this.fetch_dict[link_field].columns.push(src_field);this.fetch_dict[link_field].fields.push(tar_field);} _f.Frm.prototype.setup_client_script=function(){if(this.meta.client_script_core||this.meta.client_script||this.meta.__js){this.runclientscript('setup',this.doctype,this.docname);}} From 90376f6ce42d0e38ed3601b84430e1ab4a30619c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Jun 2012 10:31:08 +0530 Subject: [PATCH 10/14] reset to prev version --- public/js/all-app.js | 20 ++++++++------------ public/js/fields.js | 10 ++++------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/public/js/all-app.js b/public/js/all-app.js index ec43c7013d..0ee5f2bfe5 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -734,21 +734,19 @@ return v;};function LinkField(){}LinkField.prototype=new Field();LinkField.proto $(me.btn2).css('display','inline-block');else $dh(me.btn2);}} me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;} me.get_value=function(){return me.txt.value;} -$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(me.txt).change(function(event){me.wait=false;var val=me.get_value();if(!val){if(selector&&selector.display) -return;me.set_input_value('');} -setTimeout(function(){if(!me.wait){me.validate_link(val);}},100);});} +$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display) +return;me.set_input_value('');}})} LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm) var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}} LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);} if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}} me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}} _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}} -LinkField.prototype.set_input_value=function(val){var me=this;me.wait=true;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;} +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(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} -me.validate_link(val);} -LinkField.prototype.validate_link=function(val){var me=this;var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) +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) me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('

    Click here to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)}) @@ -1559,21 +1557,19 @@ return v;};function LinkField(){}LinkField.prototype=new Field();LinkField.proto $(me.btn2).css('display','inline-block');else $dh(me.btn2);}} me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;} me.get_value=function(){return me.txt.value;} -$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(me.txt).change(function(event){me.wait=false;var val=me.get_value();if(!val){if(selector&&selector.display) -return;me.set_input_value('');} -setTimeout(function(){if(!me.wait){me.validate_link(val);}},100);});} +$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display) +return;me.set_input_value('');}})} LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm) var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}} LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);} if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}} me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}} _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}} -LinkField.prototype.set_input_value=function(val){var me=this;me.wait=true;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;} +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(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} -me.validate_link(val);} -LinkField.prototype.validate_link=function(val){var me=this;var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) +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) me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('

    Click here to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)}) diff --git a/public/js/fields.js b/public/js/fields.js index b23e04bd8f..dba9e5c249 100644 --- a/public/js/fields.js +++ b/public/js/fields.js @@ -98,21 +98,19 @@ return v;};function LinkField(){}LinkField.prototype=new Field();LinkField.proto $(me.btn2).css('display','inline-block');else $dh(me.btn2);}} me.txt.field_object=this;me.input.set_input=function(val){if(val==undefined)val='';me.txt.value=val;} me.get_value=function(){return me.txt.value;} -$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(me.txt).change(function(event){me.wait=false;var val=me.get_value();if(!val){if(selector&&selector.display) -return;me.set_input_value('');} -setTimeout(function(){if(!me.wait){me.validate_link(val);}},100);});} +$(me.txt).autocomplete({source:function(request,response){wn.call({method:'webnotes.widgets.search.search_link',args:{'txt':request.term,'dt':me.df.options,'query':me.get_custom_query()},callback:function(r){response(r.results);},});},select:function(event,ui){me.set_input_value(ui.item.value);}}).data('autocomplete')._renderItem=function(ul,item){return $('
  • ').data('item.autocomplete',item).append(repl('%(label)s
    %(info)s
    ',item)).appendTo(ul);};$(this.txt).change(function(){if(!$(this).val()){if(selector&&selector.display) +return;me.set_input_value('');}})} LinkField.prototype.get_custom_query=function(){this.set_get_query();if(this.get_query){if(cur_frm) var doc=locals[cur_frm.doctype][cur_frm.docname];return this.get_query(doc,this.doctype,this.docname);}} LinkField.prototype.setup_buttons=function(){var me=this;me.btn.onclick=function(){selector.set(me,me.df.options,me.df.label);selector.show(me.txt);} if(me.btn1)me.btn1.onclick=function(){if(me.txt.value&&me.df.options){loaddoc(me.df.options,me.txt.value);}} me.can_create=0;if((!me.not_in_form)&&in_list(profile.can_create,me.df.options)){me.can_create=1;me.btn2.onclick=function(){var on_save_callback=function(new_rec){if(new_rec){var d=_f.calling_doc_stack.pop();locals[d[0]][d[1]][me.df.fieldname]=new_rec;me.refresh();if(me.grid)me.grid.refresh();me.run_trigger();}} _f.calling_doc_stack.push([me.doctype,me.docname]);new_doc(me.df.options,me.on_new,1,on_save_callback,me.doctype,me.docname,me.frm.not_in_container);}}else{$dh(me.btn2);$y($td(me.tab,0,2),{width:'0px'});}} -LinkField.prototype.set_input_value=function(val){var me=this;me.wait=true;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;} +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(locals[me.doctype][me.docname][me.df.fieldname]&&!val){me.run_trigger();return;} -me.validate_link(val);} -LinkField.prototype.validate_link=function(val){var me=this;var fetch='';if(cur_frm.fetch_dict[me.df.fieldname]) +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) me.set_fetch_values(r.fetch_values);me.run_trigger();}else{var astr='';if(in_list(profile.can_create,me.df.options))astr=repl('

    Click here to create a new %(dtl)s',{dt:me.df.options,dtl:get_doctype_label(me.df.options)}) From be7c426e154f6e4d57467b68776c4f19378a4921 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 19 Jun 2012 17:52:37 +0530 Subject: [PATCH 11/14] add parent column in filter list --- public/js/all-app.js | 3 ++- public/js/all-web.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/all-app.js b/public/js/all-app.js index 0ee5f2bfe5..8d28e84087 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -350,7 +350,8 @@ df.original_type=df.fieldtype;df.description='';df.reqd=0;if(fieldtype){df.field if(df.fieldtype=='Check'){df.fieldtype='Select';df.options='No\nYes';}else if(['Text','Text Editor','Code','Link'].indexOf(df.fieldtype)!=-1){df.fieldtype='Data';}},set_default_condition:function(df,fieldtype){if(!fieldtype){if(df.fieldtype=='Data'){this.$w.find('.condition').val('like');}else{this.$w.find('.condition').val('=');}}},get_value:function(){var me=this;var val=me.field.get_value();var cond=me.$w.find('.condition').val();if(me.field.df.original_type=='Check'){val=(val=='Yes'?1:0);} if(cond=='like'){val=val+'%';} return[me.fieldselect.$select.find('option:selected').attr('table'),me.field.df.fieldname,me.$w.find('.condition').val(),cstr(val)];}});wn.ui.FieldSelect=Class.extend({init:function(parent,doctype,filter_fields,with_blank){this.doctype=doctype;this.fields_by_name={};this.with_blank=with_blank;this.$select=$('').appendTo(parent);if(filter_fields){for(var i in filter_fields) -this.add_field_option(this.filter_fields[i])}else{this.build_options();}},build_options:function(){var me=this;me.table_fields=[];var std_filters=[{fieldname:'name',fieldtype:'Data',label:'ID',parent:me.doctype},{fieldname:'modified',fieldtype:'Date',label:'Last Modified',parent:me.doctype},{fieldname:'owner',fieldtype:'Data',label:'Created By',parent:me.doctype},{fieldname:'creation',fieldtype:'Date',label:'Created On',parent:me.doctype},{fieldname:'_user_tags',fieldtype:'Data',label:'Tags',parent:me.doctype}];if(this.with_blank){this.$select.append($('