Merge branch 'shf_rename' of github.com:webnotes/erpnext into shf_rename
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt b/erpnext/accounts/doctype/sales_invoice/sales_invoice.txt
index f66f877..5ec5552 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-04-13 11:56:18',
 		'docstatus': 0,
-		'modified': '2012-05-02 09:57:50',
+		'modified': '2012-05-04 11:56:59',
 		'modified_by': u'Administrator',
 		'owner': u'Administrator'
 	},
@@ -298,19 +298,6 @@
 
 	# DocField
 	{
-		'doctype': u'DocField',
-		'fieldname': u'posting_time',
-		'fieldtype': u'Time',
-		'label': u'Posting Time',
-		'no_copy': 1,
-		'oldfieldname': u'posting_time',
-		'oldfieldtype': u'Time',
-		'permlevel': 0,
-		'print_hide': 1
-	},
-
-	# DocField
-	{
 		'colour': u'White:FFF',
 		'default': u'Today',
 		'description': u'Enter the date by which payments from customer is expected against this invoice.',
@@ -329,6 +316,18 @@
 
 	# DocField
 	{
+		'doctype': u'DocField',
+		'fieldname': u'mode_of_payment',
+		'fieldtype': u'Select',
+		'label': u'Mode of Payment',
+		'oldfieldname': u'mode_of_payment',
+		'oldfieldtype': u'Select',
+		'options': u'link:Mode of Payment',
+		'permlevel': 0
+	},
+
+	# DocField
+	{
 		'colour': u'White:FFF',
 		'doctype': u'DocField',
 		'fieldname': u'items',
@@ -1093,6 +1092,19 @@
 
 	# DocField
 	{
+		'doctype': u'DocField',
+		'fieldname': u'posting_time',
+		'fieldtype': u'Time',
+		'label': u'Posting Time',
+		'no_copy': 1,
+		'oldfieldname': u'posting_time',
+		'oldfieldtype': u'Time',
+		'permlevel': 0,
+		'print_hide': 1
+	},
+
+	# DocField
+	{
 		'allow_on_submit': 1,
 		'colour': u'White:FFF',
 		'doctype': u'DocField',
@@ -1109,18 +1121,6 @@
 	# DocField
 	{
 		'doctype': u'DocField',
-		'fieldname': u'mode_of_payment',
-		'fieldtype': u'Select',
-		'label': u'Mode of Payment',
-		'oldfieldname': u'mode_of_payment',
-		'oldfieldtype': u'Select',
-		'options': u'link:Mode of Payment',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
 		'fieldname': u'c_form_applicable',
 		'fieldtype': u'Select',
 		'label': u'C-Form Applicable',
diff --git a/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.js b/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.js
index dd3e750..53de71c 100644
--- a/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.js
+++ b/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.js
@@ -80,14 +80,8 @@
     add_col = '';
     add_tables = '';
     sp_cond = '';
-    if(trans == 'Sales Invoice') trans = 'Sales Invoice';
-    else if(trans == 'Purchase Invoice') trans = 'Purchase Invoice';
 
-    trans_det = trans+' Detail'
-
-    if(trans == 'Sales Invoice') trans_det = 'Sales Invoice Item';
-    else if(trans == 'Purchase Invoice') trans_det = 'Purchase Invoice Item';
-    else if(trans == 'Purchase Order') trans_det = 'Purchase Order Item';
+    trans_det = trans+' Item'
 
     if(order_type != '') add_code += ' AND t1.order_type = '+order_type;
 
diff --git a/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.py b/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.py
index 278cfd6..4a7d093 100644
--- a/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.py
+++ b/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.py
@@ -39,14 +39,8 @@
 # ********************************************* SET DEFAULTS **************************************************
 # Details Table
 # --------------
-if trans == 'Sales Invoice': trans = 'Sales Invoice'
-elif trans == 'Purchase Invoice': trans = 'Purchase Invoice'
 
-trans_det = trans+' Detail'
-
-if trans == 'Sales Invoice': trans_det = 'Sales Invoice Item'
-elif trans == 'Purchase Invoice': trans_det = 'Purchase Invoice Item'
-elif trans == 'Purchase Order': trans_det = 'Purchase Order Item'
+trans_det = trans+' Item'
 
 col_names, query_val = get_obj('Trend Analyzer Control').get_single_year_query_value(fiscal_year, period, trans, trans_det)
 query_val += 'SUM(t2.qty), SUM(t2.amount)'
diff --git a/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.txt b/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.txt
index 93a60e0..a1cf3e4 100644
--- a/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.txt
+++ b/erpnext/accounts/search_criteria/trend_analyzer/trend_analyzer.txt
@@ -3,9 +3,9 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-04-03 12:49:53',
+		'creation': '2012-04-23 12:46:00',
 		'docstatus': 0,
-		'modified': '2012-04-03 12:49:53',
+		'modified': '2012-05-04 12:49:43',
 		'modified_by': u'Administrator',
 		'owner': u'saumil@webnotestech.com'
 	},
@@ -30,4 +30,4 @@
 		'doctype': 'Search Criteria',
 		'name': u'trend_analyzer'
 	}
-]
+]
\ No newline at end of file
diff --git a/erpnext/patches/may_2012/renamedt_in_custom_search_criteria.py b/erpnext/patches/may_2012/renamedt_in_custom_search_criteria.py
new file mode 100644
index 0000000..3ac1f8e
--- /dev/null
+++ b/erpnext/patches/may_2012/renamedt_in_custom_search_criteria.py
@@ -0,0 +1,99 @@
+def execute():
+	import webnotes
+	rendt = {
+		'Receivable Voucher'		:	'Sales Invoice',
+		'RV Detail'					:	'Sales Invoice Item',
+		'RV Tax Detail'				:	'Sales Taxes and Charges',
+		'Payable Voucher'			:	'Purchase Invoice',
+		'PV Detail'					:	'Purchase Invoice Item',
+		'Purchase Tax Detail'		:	'Purchase Taxes and Charges',
+		'Indent'					:	'Purchase Request',
+		'Indent Detail'				:	'Purchase Request Item',
+		'QA Inspection Report'		:	'Quality Inspection',
+		'Ticket'					:	'Task',
+		'Manage Account'			:	'Global Defaults',
+		'ToDo Item'					:	'ToDo',
+		'Term'						:	'Terms and Conditions',
+		'Static Parameter Detail'	:	'SMS Parameter',
+		'SS Earning Detail'			:	'Salary Slip Earning',
+		'SS Deduction Detail'		:	'Salary Slip Deduction',
+		'Sales Order Detail'		:	'Sales Order Item',
+		'Sales BOM Detail'			:	'Sales BOM Item',
+		'Return Detail'				:	'Sales and Purchase Return Item',
+		'Ref Rate Detail'			:	'Item Price',
+		'Receiver Detail'			:	'SMS Receiver',
+		'Quotation Detail'			:	'Quotation Item',
+		'QA Specification Detail'	:	'Quality Inspection Reading',
+		'Purchase Receipt Detail'	:	'Purchase Receipt Item',
+		'Purchase Other Charges'	:	'Purchase Taxes and Charges Master',
+		'PR Raw Material Detail'	:	'Purchase Receipt Item Supplied',
+		'PP SO Detail'				:	'Production Plan Sales Order',
+		'PP Detail'					:	'Production Plan Item',
+		'PO Raw Material Detail'	:	'Purchase Order Item Supplied',
+		'PO Detail'					:	'Purchase Order Item', 
+		'Packing Slip Detail'		:	'Packing Slip Item',
+		'Other Charges'				:	'Sales Taxes and Charges Master',
+		'Order Lost Reason'			:	'Quotation Lost Reason',
+		'Manage Account'			:	'Global Defaults',
+		'Maintenance Visit Detail'	:	'Maintenance Visit Purpose',
+		'Ledger Balance Export'		:	'Multi Ledger Report',
+		'LC PR Detail'				:	'Landed Cost Purchase Receipt',
+		'Landed Cost Detail'		:	'Landed Cost Item',
+		'KRA Template'				:	'Appraisal Template',
+		'KRA Sheet'					:	'Appraisal Template Goal',
+		'Item Specification Detail' :	'Item Quality Inspection Parameter',
+		'Item Maintenance Detail'	:	'Maintenance Schedule Item',
+		'IR Payment Detail'			:	'Payment to Invoice Matching Tool Detail',
+		'Internal Reconciliation'	:	'Payment to Invoice Matching Tool',
+		'Installed Item Details'	:	'Installation Note Item',
+		'Holiday List Detail'		:	'Holiday',
+		'Follow up'					:	'Communication Log',
+		'Flat BOM Detail'			:	'BOM Explosion Item',
+		'Expense Voucher Detail'	:	'Expense Claim Detail',
+		'Expense Voucher'			:	'Expense Claim',
+		'Expense Type'				:	'Expense Claim Type',
+		'Enquiry Detail'			:	'Opportunity Item',
+		'Enquiry'					:	'Opportunity',
+		'Earning Detail'			:	'Salary Structure Earning',
+		'DocLayerField'				:	'Customize Form Field',
+		'DocLayer'					:	'Customize Form',
+		'Delivery Note Detail'		:	'Delivery Note Item',
+		'Deduction Detail'			:	'Salary Structure Deduction',
+		'Comment Widget Record'		:	'Comment',
+		'BOM Material'				:	'BOM Item',
+		'Bill Of Materials'			:	'BOM',
+		'Appraisal Detail'			:	'Appraisal Goal',
+		'Advance Allocation Detail' :	'Purchase Invoice Advance',
+		'Advance Adjustment Detail' :	'Sales Invoice Advance',
+		'Ledger Detail'				:	'Multi Ledger Report Detail',
+		'TA Control'				:	'Trend Analyzer Control',
+		'Sales and Purchase Return Wizard'	: 'Sales and Purchase Return Tool',
+		'Educational Qualifications Detail' : 'Employee Education',
+		'Delivery Note Packing Detail'		: 'Delivery Note Packing Item',
+		'Experience In Company Detail'		: 'Employee Internal Work History',
+		'Professional Training Details'		: 'Employee Training',
+		'Previous Experience Detail'		: 'Employee External Work History',
+	}
+
+	for d in rendt:
+		webnotes.conn.sql("""
+			update
+				`tabSearch Criteria` 
+			set 
+				doc_type		= replace(doc_type, %s, %s), 
+				filters			= replace(filters, %s, %s), 
+				columns			= replace(columns, %s, %s), 
+				parent_doc_type = replace(parent_doc_type, %s, %s), 
+				add_cond		= replace(add_cond, %s, %s), 
+				add_col			= replace(add_col, %s, %s), 
+				add_tab			= replace(add_tab, %s, %s), 
+				dis_filters		= replace(dis_filters, %s, %s), 
+				group_by		= replace(group_by, %s, %s), 
+				sort_by			= replace(sort_by, %s, %s), 
+				report_script	= replace(report_script, %s, %s), 
+				server_script	= replace(server_script, %s, %s), 
+				custom_query	= replace(custom_query, %s, %s)
+		""", (d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d], 
+				d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d], d, rendt[d]))
+
+
diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py
index d6d689f..01f4a0e 100644
--- a/erpnext/patches/patch_list.py
+++ b/erpnext/patches/patch_list.py
@@ -327,5 +327,10 @@
 		'patch_file': 'cleanup_notification_control',
 		'description': 'cleanup notification control'
 	},
+	{
+		'patch_module': 'patches.may_2012',
+		'patch_file': 'renamedt_in_custom_search_criteria',
+		'description': 'raname dt in custom search criteria'
+	},
 
 ]
diff --git a/erpnext/setup/doctype/setup_control/setup_control.py b/erpnext/setup/doctype/setup_control/setup_control.py
index d5832c4..bcdd093 100644
--- a/erpnext/setup/doctype/setup_control/setup_control.py
+++ b/erpnext/setup/doctype/setup_control/setup_control.py
@@ -81,7 +81,12 @@
 
 		# Set 
 		self.set_defaults(def_args)
-		self.set_cp_defaults(**args)
+		
+		cp_args = {}
+		for k in ['industry', 'country', 'timezone', 'company_name']:
+			cp_args[k] = args[k]
+		
+		self.set_cp_defaults(**cp_args)
 
 		self.create_feed_and_todo()
 
diff --git a/erpnext/stock/doctype/landed_cost_item/landed_cost_item.txt b/erpnext/stock/doctype/landed_cost_item/landed_cost_item.txt
index 4157039..06f765d 100644
--- a/erpnext/stock/doctype/landed_cost_item/landed_cost_item.txt
+++ b/erpnext/stock/doctype/landed_cost_item/landed_cost_item.txt
@@ -3,9 +3,9 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-03-27 14:36:33',
+		'creation': '2012-05-03 11:00:55',
 		'docstatus': 0,
-		'modified': '2012-03-27 14:36:33',
+		'modified': '2012-05-04 13:02:26',
 		'modified_by': u'Administrator',
 		'owner': u'wasim@webnotestech.com'
 	},
@@ -21,7 +21,7 @@
 		'section_style': u'Simple',
 		'server_code_error': u' ',
 		'show_in_menu': 0,
-		'version': 2
+		'version': 1
 	},
 
 	# These values are common for all DocField
diff --git a/erpnext/stock/doctype/landed_cost_master/landed_cost_master.js b/erpnext/stock/doctype/landed_cost_master/landed_cost_master.js
index 3cad944..03e8a39 100644
--- a/erpnext/stock/doctype/landed_cost_master/landed_cost_master.js
+++ b/erpnext/stock/doctype/landed_cost_master/landed_cost_master.js
@@ -23,4 +23,8 @@
 
 cur_frm.cscript.refresh = function(doc, cdt, cdn) {
    
+}
+
+cur_frm.fields_dict.landed_cost.grid.get_field('account_head').get_query = function(doc, cdt, cdn) {
+	return 'SELECT tabAccount.name FROM tabAccount WHERE tabAccount.group_or_ledger="Ledger" AND tabAccount.docstatus != 2 AND (tabAccount.account_type = "Tax" OR tabAccount.account_type = "Chargeable" or (tabAccount.is_pl_account = "Yes" and tabAccount.debit_or_credit = "Debit")) AND  tabAccount.name LIKE "%s"';
 }
\ No newline at end of file
diff --git a/erpnext/stock/doctype/landed_cost_master_detail/landed_cost_master_detail.txt b/erpnext/stock/doctype/landed_cost_master_detail/landed_cost_master_detail.txt
index 1beccea..74e47e1 100644
--- a/erpnext/stock/doctype/landed_cost_master_detail/landed_cost_master_detail.txt
+++ b/erpnext/stock/doctype/landed_cost_master_detail/landed_cost_master_detail.txt
@@ -3,9 +3,9 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-03-27 14:36:34',
+		'creation': '2012-05-03 11:00:55',
 		'docstatus': 0,
-		'modified': '2012-03-27 14:36:34',
+		'modified': '2012-05-04 13:02:35',
 		'modified_by': u'Administrator',
 		'owner': u'Administrator'
 	},
@@ -19,13 +19,12 @@
 		'name': '__common__',
 		'section_style': u'Simple',
 		'server_code_error': u' ',
-		'version': 2
+		'version': 1
 	},
 
 	# These values are common for all DocField
 	{
 		'doctype': u'DocField',
-		'fieldtype': u'Data',
 		'name': '__common__',
 		'oldfieldtype': u'Data',
 		'parent': u'Landed Cost Master Detail',
@@ -44,14 +43,17 @@
 	{
 		'doctype': u'DocField',
 		'fieldname': u'account_head',
+		'fieldtype': u'Link',
 		'label': u'Account Head',
-		'oldfieldname': u'account_head'
+		'oldfieldname': u'account_head',
+		'options': u'Account'
 	},
 
 	# DocField
 	{
 		'doctype': u'DocField',
 		'fieldname': u'description',
+		'fieldtype': u'Data',
 		'label': u'Description',
 		'oldfieldname': u'description',
 		'width': u'300px'
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 86cb099..ee81518 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -47,36 +47,35 @@
 
 		return content
 
-	def convert_into_list(self, data):
+	def convert_into_list(self, data, submit = 1):
 		"""Convert csv data into list"""
-		count = 1
+		count = 2
 		for s in data:
-			if s[0].strip() != 'Item Code': # remove the labels
-				# validate
-				if len(s) != 4:
-					msgprint("Data entered at Row No " + cstr(count) + " in Attachment File is not in correct format.", raise_exception=1)
-					self.validated = 0
-				self.validate_item(s[0], count)
-				self.validate_warehouse(s[1], count)
+			if count == 2: continue
+			# validate
+			if (submit and len(s) != 4) or (not submit and len(s) != 6):
+				msgprint("Data entered at Row No " + cstr(count) + " in Attachment File is not in correct format.", raise_exception=1)
+				self.validated = 0
+			self.validate_item(s[0], count)
+			self.validate_warehouse(s[1], count)
 			
-				self.data.append(s)
-				count += 1
+			self.data.append(s)
+			count += 1
 			
 		if not self.validated:
 			raise Exception
 
 
-	def get_reconciliation_data(self,submit = 0):
+	def get_reconciliation_data(self,submit = 1):
 		"""Read and validate csv data"""
 		import csv 
 		data = csv.reader(self.get_csv_file_data().splitlines())
-		self.convert_into_list(data)
+		self.convert_into_list(data, submit)
 		
 
 	def validate_item(self, item, count):
 		""" Validate item exists and non-serialized"""
-		det = sql("select item_code, has_serial_no from `tabItem` \
-				where name = %s", cstr(item), as_dict = 1)
+		det = sql("select item_code, has_serial_no from `tabItem` where name = %s", cstr(item), as_dict = 1)
 		if not det:
 			msgprint("Item: " + cstr(item) + " mentioned at Row No. " + cstr(count) + "does not exist in the system")
 			self.validated = 0
@@ -176,7 +175,7 @@
 		"""Add diffs column in attached file"""
 		
 		# add header
-		out = "'Item Code', 'Warehouse', 'Qty', 'Valuation Rate', 'Qty Diff', 'Val Rate Diff'"
+		out = "Item Code, Warehouse, Qty, Valuation Rate, Qty Diff, Val Rate Diff"
 		
 		# add data
 		for d in self.data:
@@ -199,5 +198,5 @@
 
 
 	def on_cancel(self):
-		self.validate()
+		self.get_reconciliation_data(submit = 0)
 		self.do_stock_reco(is_submit = -1)
diff --git a/erpnext/utilities/doctype/contact/contact.js b/erpnext/utilities/doctype/contact/contact.js
index 9244b79..ae06ed4 100644
--- a/erpnext/utilities/doctype/contact/contact.js
+++ b/erpnext/utilities/doctype/contact/contact.js
@@ -15,7 +15,7 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 //--------- ONLOAD -------------
-cur_frm.cscript.onload = function(doc, cdt, cdn) {
+cur_frm.cscript.onload = function(doc, cdt, cdn) {	
 	if(doc.customer) cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
 	if(doc.supplier) cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
 
diff --git a/js/all-app.js b/js/all-app.js
index 09a3020..65ca124 100644
--- a/js/all-app.js
+++ b/js/all-app.js
@@ -1314,7 +1314,7 @@
 delete locals[dt][dn];}
 function get_local(dt,dn){return locals[dt]?locals[dt][dn]:null;}
 LocalDB.sync=function(list){if(list._kl)list=expand_doclist(list);for(var i=0;i<list.length;i++){var d=list[i];if(!d.name)
-d.name=LocalDB.get_localname(d.doctype);LocalDB.add(d.doctype,d.name);locals[d.doctype][d.name]=d;if(d.doctype=='DocField')wn.meta.add_field(d);if(d.localname){wn.model.new_names[d.localname]=d.name;console.log(d.localname);$(document).trigger('rename',[d.doctype,d.localname,d.name]);delete locals[d.doctype][d.localname];}}}
+d.name=LocalDB.get_localname(d.doctype);LocalDB.add(d.doctype,d.name);locals[d.doctype][d.name]=d;if(d.doctype=='DocField')wn.meta.add_field(d);if(d.localname){wn.model.new_names[d.localname]=d.name;$(document).trigger('rename',[d.doctype,d.localname,d.name]);delete locals[d.doctype][d.localname];}}}
 local_name_idx={};LocalDB.get_localname=function(doctype){if(!local_name_idx[doctype])local_name_idx[doctype]=1;var n='New '+get_doctype_label(doctype)+' '+local_name_idx[doctype];local_name_idx[doctype]++;return n;}
 LocalDB.set_default_values=function(doc){var doctype=doc.doctype;var docfields=wn.meta.docfield_list[doctype];if(!docfields){return;}
 var fields_to_refresh=[];for(var fid=0;fid<docfields.length;fid++){var f=docfields[fid];if(!in_list(no_value_fields,f.fieldtype)&&doc[f.fieldname]==null){var v=LocalDB.get_default_value(f.fieldname,f.fieldtype,f['default']);if(v){doc[f.fieldname]=v;fields_to_refresh.push(f.fieldname);}}}
@@ -1686,7 +1686,7 @@
 d.onhide=function(){if(_f.cur_grid){_f.cur_grid.refresh_row(_f.cur_grid_ridx,me.dn);}
 if(wn.container.page.frm){cur_frm=wn.container.page.frm;}
 if(me.cur_frm.cscript.hide_dialog){me.cur_frm.cscript.hide_dialog();}
-console.log(me.cur_frm.wrapper);$(me.cur_frm.page_layout.wrapper).toggle(false);}
+$(me.cur_frm.page_layout.wrapper).toggle(false);}
 this.dialog=d;}
 _f.edit_record=function(dt,dn){if(!_f.frm_dialog){_f.frm_dialog=new _f.FrmDialog();}
 var d=_f.frm_dialog;wn.model.with_doctype(dt,function(){wn.model.with_doc(dt,dn,function(dn){if(!_f.frms[dt]){_f.frms[dt]=new _f.Frm(dt,d.body);}
@@ -1712,8 +1712,7 @@
 /*
  *	lib/js/legacy/widgets/form/form.js
  */
-wn.provide('_f');_f.frms={};_f.Frm=function(doctype,parent){this.docname='';this.doctype=doctype;this.display=0;var me=this;this.is_editable={};this.opendocs={};this.sections=[];this.grids=[];this.cscript={};this.pformat={};this.fetch_dict={};this.parent=parent;this.tinymce_id_list=[];this.setup_meta(doctype);var me=this;$(document).bind('rename',function(event,dt,old_name,new_name){console.log(arguments)
-if(dt==me.doctype)
+wn.provide('_f');_f.frms={};_f.Frm=function(doctype,parent){this.docname='';this.doctype=doctype;this.display=0;var me=this;this.is_editable={};this.opendocs={};this.sections=[];this.grids=[];this.cscript={};this.pformat={};this.fetch_dict={};this.parent=parent;this.tinymce_id_list=[];this.setup_meta(doctype);var me=this;$(document).bind('rename',function(event,dt,old_name,new_name){if(dt==me.doctype)
 me.rename_notify(dt,old_name,new_name)});}
 _f.Frm.prototype.check_doctype_conflict=function(docname){var me=this;if(this.doctype=='DocType'&&docname=='DocType'){msgprint('Allowing DocType, DocType. Be careful!')}else if(this.doctype=='DocType'){if(wn.views.formview[docname]){msgprint("Cannot open DocType when its instance is open")
 throw'doctype open conflict'}}else{if(wn.views.formview.DocType&&wn.views.formview.DocType.frm.opendocs[this.doctype]){msgprint("Cannot open instance when its DocType is open")
@@ -1809,7 +1808,7 @@
 var ret_fn=function(r){me.savingflag=false;if(user=='Guest'&&!r.exc){$dh(me.page_layout.wrapper);$ds(me.saved_wrapper);me.saved_wrapper.innerHTML='<div style="padding: 150px 16px; text-align: center; font-size: 14px;">'
 +(cur_frm.message_after_save?cur_frm.message_after_save:'Your information has been sent. Thank you!')
 +'</div>';return;}
-if(!me.meta.istable){me.refresh();}
+if(!me.meta.istable){me.refresh(r.docname);}
 if(call_back){call_back(r);}}
 var me=this;var ret_fn_err=function(r){var doc=locals[me.doctype][me.docname];me.savingflag=false;ret_fn(r);}
 this.savingflag=true;if(this.docname&&validated){scroll(0,0);return this.savedoc(save_action,ret_fn,ret_fn_err);}}
@@ -2009,7 +2008,7 @@
 _p.go=function(html){var d=document.createElement('div')
 d.innerHTML=html
 $(d).printElement();}
-_p.preview=function(html){var w=window.open('');w.document.write(html)
+_p.preview=function(html){var w=window.open('');if(!w)return;w.document.write(html)
 w.document.close();}
 $.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);}
diff --git a/js/all-web.js b/js/all-web.js
index 24ee8f4..00d396a 100644
--- a/js/all-web.js
+++ b/js/all-web.js
@@ -758,7 +758,7 @@
 delete locals[dt][dn];}
 function get_local(dt,dn){return locals[dt]?locals[dt][dn]:null;}
 LocalDB.sync=function(list){if(list._kl)list=expand_doclist(list);for(var i=0;i<list.length;i++){var d=list[i];if(!d.name)
-d.name=LocalDB.get_localname(d.doctype);LocalDB.add(d.doctype,d.name);locals[d.doctype][d.name]=d;if(d.doctype=='DocField')wn.meta.add_field(d);if(d.localname){wn.model.new_names[d.localname]=d.name;console.log(d.localname);$(document).trigger('rename',[d.doctype,d.localname,d.name]);delete locals[d.doctype][d.localname];}}}
+d.name=LocalDB.get_localname(d.doctype);LocalDB.add(d.doctype,d.name);locals[d.doctype][d.name]=d;if(d.doctype=='DocField')wn.meta.add_field(d);if(d.localname){wn.model.new_names[d.localname]=d.name;$(document).trigger('rename',[d.doctype,d.localname,d.name]);delete locals[d.doctype][d.localname];}}}
 local_name_idx={};LocalDB.get_localname=function(doctype){if(!local_name_idx[doctype])local_name_idx[doctype]=1;var n='New '+get_doctype_label(doctype)+' '+local_name_idx[doctype];local_name_idx[doctype]++;return n;}
 LocalDB.set_default_values=function(doc){var doctype=doc.doctype;var docfields=wn.meta.docfield_list[doctype];if(!docfields){return;}
 var fields_to_refresh=[];for(var fid=0;fid<docfields.length;fid++){var f=docfields[fid];if(!in_list(no_value_fields,f.fieldtype)&&doc[f.fieldname]==null){var v=LocalDB.get_default_value(f.fieldname,f.fieldtype,f['default']);if(v){doc[f.fieldname]=v;fields_to_refresh.push(f.fieldname);}}}