Merge branch 'stable' into latest
diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
index dc86658..aa12ab8 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
@@ -23,9 +23,6 @@
 
  		hide_field(['customer_address', 'contact_person', 'customer_name', 'address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
 
-		// defined in sales_common.js
-		cur_frm.cscript.update_item_details(doc, cdt, cdn);		
-		
 		//for previously created sales invoice, set required field related to pos
 		if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn);
 
@@ -33,21 +30,22 @@
 }
 
 cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
+	var callback = null;
 	if(doc.customer && doc.__islocal) {
 		// called from mapper, update the account names for items and customer
-		$c_obj(make_doclist(doc.doctype,doc.name),
-			'load_default_accounts','',
-			function(r,rt) {
-				refresh_field('entries');
-				cur_frm.cscript.customer(doc,dt,dn);
-			}
-		);
+		callback = function(doc, dt, dn) {
+			$c_obj(make_doclist(doc.doctype,doc.name),
+				'load_default_accounts','',
+				function(r,rt) {
+					refresh_field('entries');
+					cur_frm.cscript.customer(doc,dt,dn);
+				}
+			);
+		}
 	}
-
-	if(!doc.customer && doc.__islocal) {
-		// new -- load default taxes
-		cur_frm.cscript.load_taxes(doc, cdt, cdn);
-	}
+	// defined in sales_common.js
+	cur_frm.cscript.update_item_details(doc, cdt, cdn, callback);		
+		
 }
 
 
diff --git a/erpnext/home/page/my_company/my_company.py b/erpnext/home/page/my_company/my_company.py
index 8070c9d..b949c05 100644
--- a/erpnext/home/page/my_company/my_company.py
+++ b/erpnext/home/page/my_company/my_company.py
@@ -41,6 +41,9 @@
 	if cint(webnotes.conn.get_value('Control Panel', None, 'sync_with_gateway')):
 		from server_tools.gateway_utils import remove_user_gateway
 		remove_user_gateway(args['user'])
+	
+	webnotes.login_manager.logout(user=args['user'])
+
 
 @webnotes.whitelist()
 def add_user(args):
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 9ba743d..e39b5f0 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -32,15 +32,11 @@
 		}
 	}
 
-	// defined in sales_common.js
-	cur_frm.cscript.update_item_details(doc, cdt, cdn);
-
 }
 
 cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
-	// load default charges
-	if(doc.__islocal && !getchildren('RV Tax Detail', doc.name, 'other_charges', doc.doctype).length)
-		cur_frm.cscript.load_taxes(doc, cdt, cdn);
+	// defined in sales_common.js
+	cur_frm.cscript.update_item_details(doc, cdt, cdn);
 }
 
 // hide - unhide fields based on lead or customer..
diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js
index 57f379c..cdcec5b 100644
--- a/erpnext/selling/doctype/sales_common/sales_common.js
+++ b/erpnext/selling/doctype/sales_common/sales_common.js
@@ -6,18 +6,23 @@
 // cur_frm.cscript.sales_team_fname - Sales Team fieldname
 
 // ============== Load Default Taxes ===================
-cur_frm.cscript.load_taxes = function(doc, cdt, cdn) {
+cur_frm.cscript.load_taxes = function(doc, cdt, cdn, callback) {
 	// run if this is not executed from dt_map...
-	if(doc.customer) return;
+	doc = locals[doc.doctype][doc.name];
+	if(doc.customer || getchildren('RV Tax Detail', doc.name, 'other_charges', doc.doctype).length) {
+		if(callback) callback(doc, cdt, cdn);
+		return;
+	}
 	$c_obj([doc],'load_default_taxes','',function(r,rt){
-		 refresh_field('other_charges');
+		refresh_field('other_charges');
+		if(callback) callback(doc, cdt, cdn);
 	});
 }
 
 
 // Gets called after existing item details are update to fill in
 // remaining default values
-cur_frm.cscript.load_defaults = function(doc, dt, dn) {
+cur_frm.cscript.load_defaults = function(doc, dt, dn, callback) {
 	if(!cur_frm.doc.__islocal) { return; }
 
 	doc = locals[doc.doctype][doc.name];
@@ -31,11 +36,13 @@
 		LocalDB.set_default_values(children[i]);
 	}
 	refresh_field(cur_frm.cscript.fname);
+	cur_frm.cscript.load_taxes(doc, dt, dn, callback);
 }
 
 
 // Update existing item details
-cur_frm.cscript.update_item_details = function(doc, dt, dn) {
+cur_frm.cscript.update_item_details = function(doc, dt, dn, callback) {
+	doc = locals[doc.doctype][doc.name];
 	if(!cur_frm.doc.__islocal) return;
 	var children = getchildren(cur_frm.cscript.tname, doc.name, cur_frm.cscript.fname);
 	if(children) {
@@ -44,7 +51,7 @@
 			if(!r.exc) {
 				refresh_field(cur_frm.cscript.fname);
 				doc = locals[doc.doctype][doc.name];
-				cur_frm.cscript.load_defaults(doc, dt, dn);
+				cur_frm.cscript.load_defaults(doc, dt, dn, callback);
 			}
 		});
 	}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 59f8b84..f5f8b58 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -23,15 +23,12 @@
 		hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group','shipping_address']);
 	}
 
-	// defined in sales_common.js
-	cur_frm.cscript.update_item_details(doc, cdt, cdn);
 }
 
 cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
 	if(doc.__islocal) {
-		if(doc.quotation) cur_frm.cscript['Pull Quotation Details'](doc,cdt,cdn);
-	} else {
-	cur_frm.cscript.load_taxes(doc, cdt, cdn);
+		// defined in sales_common.js
+		cur_frm.cscript.update_item_details(doc, cdt, cdn, callback);
 	}
 }
 
diff --git a/erpnext/selling/search_criteria/customer_address_contact/customer_address_contact.txt b/erpnext/selling/search_criteria/customer_address_contact/customer_address_contact.txt
index 9e0a715..99890b7 100644
--- a/erpnext/selling/search_criteria/customer_address_contact/customer_address_contact.txt
+++ b/erpnext/selling/search_criteria/customer_address_contact/customer_address_contact.txt
@@ -3,34 +3,34 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-01-23 18:28:40',
+		'creation': '2012-02-13 11:28:45',
 		'docstatus': 0,
-		'modified': '2012-01-23 18:28:40',
-		'modified_by': 'Administrator',
-		'owner': 'Administrator'
+		'modified': '2012-02-13 11:28:45',
+		'modified_by': u'Administrator',
+		'owner': u'Administrator'
 	},
 
 	# These values are common for all Search Criteria
 	{
-		'add_col': "`tabAddress`.address_line1 AS 'Address Line 1'\n`tabAddress`.address_line2 AS 'Address Line 2'\n`tabAddress`.city AS 'City'\n`tabAddress`.state AS 'State'\n`tabAddress`.pincode AS 'Pincode'\n`tabAddress`.country AS 'Country'\n`tabContact`.first_name AS 'Contact First Name'\n`tabContact`.last_name AS 'Contact Last Name'\n`tabContact`.phone AS 'Contact Phone'\n`tabContact`.mobile_no AS 'Contact Mobile'\n`tabContact`.email_id AS 'Contact Email'",
-		'add_cond': '`tabAddress`.customer=`tabCustomer`.name\nifnull(`tabAddress`.is_primary_address, 0)=1\n`tabContact`.customer=`tabCustomer`.name\nifnull(`tabContact`.is_primary_contact, 0)=1',
-		'add_tab': '`tabAddress`\n`tabContact`',
-		'columns': 'Customer\x01ID,Customer\x01Customer Name',
-		'criteria_name': 'Customer Address Contact',
-		'doc_type': 'Customer',
+		'add_col': u"`tabAddress`.address_line1 AS 'Address Line 1'\n`tabAddress`.address_line2 AS 'Address Line 2'\n`tabAddress`.city AS 'City'\n`tabAddress`.state AS 'State'\n`tabAddress`.pincode AS 'Pincode'\n`tabAddress`.country AS 'Country'\n`tabContact`.first_name AS 'Contact First Name'\n`tabContact`.last_name AS 'Contact Last Name'\n`tabContact`.phone AS 'Contact Phone'\n`tabContact`.mobile_no AS 'Contact Mobile'\n`tabContact`.email_id AS 'Contact Email'",
+		'add_cond': u'`tabAddress`.customer=`tabCustomer`.name\nifnull(`tabAddress`.is_primary_address, 0)=1\n`tabContact`.customer=`tabCustomer`.name\nifnull(`tabContact`.is_primary_contact, 0)=1',
+		'add_tab': u'`tabAddress`\n`tabContact`',
+		'columns': u'Customer\x01ID,Customer\x01Customer Name',
+		'criteria_name': u'Customer Address Contact',
+		'doc_type': u'Customer',
 		'doctype': 'Search Criteria',
-		'filters': "{'Customer\x01Saved':1,'Customer\x01Submitted':1}",
-		'module': 'Selling',
+		'filters': u"{'Customer\x01Saved':1,'Customer\x01Submitted':1}",
+		'module': u'Selling',
 		'name': '__common__',
 		'page_len': 50,
-		'sort_by': '`tabCustomer`.`customer_name`',
-		'sort_order': 'ASC',
-		'standard': 'Yes'
+		'sort_by': u'`tabCustomer`.`customer_name`',
+		'sort_order': u'ASC',
+		'standard': u'Yes'
 	},
 
 	# Search Criteria, customer_address_contact
 	{
 		'doctype': 'Search Criteria',
-		'name': 'customer_address_contact'
+		'name': u'customer_address_contact'
 	}
 ]
\ No newline at end of file
diff --git a/erpnext/setup/doctype/authorization_rule/authorization_rule.js b/erpnext/setup/doctype/authorization_rule/authorization_rule.js
index 54863ec..21f0848 100644
--- a/erpnext/setup/doctype/authorization_rule/authorization_rule.js
+++ b/erpnext/setup/doctype/authorization_rule/authorization_rule.js
@@ -72,7 +72,7 @@
 // System User Trigger
 // -------------------
 cur_frm.fields_dict['system_user'].get_query = function(doc) {
-  return 'SELECT tabProfile.name FROM tabProfile WHERE tabProfile.name not in ("Administrator","Guest") AND tabProfile.%(key)s LIKE "%s" LIMIT 50'
+  return 'SELECT tabProfile.name FROM tabProfile WHERE tabProfile.name not in ("Administrator","Guest") AND tabProfile.docstatus != 2 AND tabProfile.enabled = 1 AND tabProfile.%(key)s LIKE "%s" LIMIT 50'
 }
 
 
@@ -86,7 +86,7 @@
 // Approving User Trigger
 // -----------------------
 cur_frm.fields_dict['approving_user'].get_query = function(doc) {
-  return 'SELECT tabProfile.name FROM tabProfile WHERE tabProfile.name not in ("Administrator","Guest") AND tabProfile.%(key)s LIKE "%s" LIMIT 50'
+  return 'SELECT tabProfile.name FROM tabProfile WHERE tabProfile.name not in ("Administrator","Guest") AND tabProfile.docstatus != 2 AND tabProfile.enabled = 1 AND tabProfile.%(key)s LIKE "%s" LIMIT 50'
 }
 
 
@@ -106,4 +106,4 @@
     return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) and `tabItem`.is_sales_item = "Yes" and tabItem.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` DESC LIMIT 50';
   else
     return 'SELECT `tabItem`.`name` FROM `tabItem` WHERE `tabItem`.`name` = "cheating done to avoid null" ORDER BY `tabItem`.`name` DESC LIMIT 50';
-}
\ No newline at end of file
+}
diff --git a/erpnext/stock/DocType Mapper/Delivery Note-Packing Slip/Delivery Note-Packing Slip.txt b/erpnext/stock/DocType Mapper/Delivery Note-Packing Slip/Delivery Note-Packing Slip.txt
index 171e08f..baf2b74 100644
--- a/erpnext/stock/DocType Mapper/Delivery Note-Packing Slip/Delivery Note-Packing Slip.txt
+++ b/erpnext/stock/DocType Mapper/Delivery Note-Packing Slip/Delivery Note-Packing Slip.txt
@@ -3,91 +3,91 @@
 
 	# These values are common in all dictionaries
 	{
-		'creation': '2012-02-02 11:35:53',
+		'creation': '2012-02-13 11:28:48',
 		'docstatus': 0,
-		'modified': '2012-02-02 11:35:53',
-		'modified_by': 'Administrator',
-		'owner': 'Administrator'
+		'modified': '2012-02-13 11:28:48',
+		'modified_by': u'Administrator',
+		'owner': u'Administrator'
 	},
 
 	# These values are common for all Table Mapper Detail
 	{
-		'doctype': 'Table Mapper Detail',
+		'doctype': u'Table Mapper Detail',
 		'name': '__common__',
-		'parent': 'Delivery Note-Packing Slip',
-		'parentfield': 'table_mapper_details',
-		'parenttype': 'DocType Mapper'
+		'parent': u'Delivery Note-Packing Slip',
+		'parentfield': u'table_mapper_details',
+		'parenttype': u'DocType Mapper'
 	},
 
 	# These values are common for all Field Mapper Detail
 	{
-		'doctype': 'Field Mapper Detail',
+		'doctype': u'Field Mapper Detail',
 		'name': '__common__',
-		'parent': 'Delivery Note-Packing Slip',
-		'parentfield': 'field_mapper_details',
-		'parenttype': 'DocType Mapper'
+		'parent': u'Delivery Note-Packing Slip',
+		'parentfield': u'field_mapper_details',
+		'parenttype': u'DocType Mapper'
 	},
 
 	# These values are common for all DocType Mapper
 	{
 		'doctype': u'DocType Mapper',
-		'from_doctype': 'Delivery Note',
-		'module': 'Stock',
+		'from_doctype': u'Delivery Note',
+		'module': u'Stock',
 		'name': '__common__',
 		'ref_doc_submitted': 1,
-		'to_doctype': 'Packing Slip'
+		'to_doctype': u'Packing Slip'
 	},
 
 	# DocType Mapper, Delivery Note-Packing Slip
 	{
 		'doctype': u'DocType Mapper',
-		'name': 'Delivery Note-Packing Slip'
+		'name': u'Delivery Note-Packing Slip'
 	},
 
 	# Field Mapper Detail
 	{
-		'doctype': 'Field Mapper Detail',
-		'from_field': 'name',
-		'map': 'Yes',
+		'doctype': u'Field Mapper Detail',
+		'from_field': u'name',
+		'map': u'Yes',
 		'match_id': 0,
-		'to_field': 'delivery_note'
+		'to_field': u'delivery_note'
 	},
 
 	# Field Mapper Detail
 	{
-		'doctype': 'Field Mapper Detail',
-		'from_field': 'qty',
-		'map': 'No',
+		'doctype': u'Field Mapper Detail',
+		'from_field': u'qty',
+		'map': u'No',
 		'match_id': 1,
-		'to_field': 'qty'
+		'to_field': u'qty'
 	},
 
 	# Field Mapper Detail
 	{
-		'doctype': 'Field Mapper Detail',
-		'from_field': 'naming_series',
-		'map': 'No',
+		'doctype': u'Field Mapper Detail',
+		'from_field': u'naming_series',
+		'map': u'No',
 		'match_id': 0,
-		'to_field': 'naming_series'
+		'to_field': u'naming_series'
 	},
 
 	# Table Mapper Detail
 	{
-		'doctype': 'Table Mapper Detail',
-		'from_table': 'Delivery Note',
+		'doctype': u'Table Mapper Detail',
+		'from_table': u'Delivery Note',
 		'match_id': 0,
-		'to_table': 'Packing Slip',
-		'validation_logic': 'docstatus=1'
+		'to_table': u'Packing Slip',
+		'validation_logic': u'docstatus=1'
 	},
 
 	# Table Mapper Detail
 	{
-		'doctype': 'Table Mapper Detail',
-		'from_field': 'delivery_note_details',
-		'from_table': 'Delivery Note Detail',
+		'doctype': u'Table Mapper Detail',
+		'from_field': u'delivery_note_details',
+		'from_table': u'Delivery Note Detail',
 		'match_id': 1,
-		'to_field': 'item_details',
-		'to_table': 'Packing Slip Detail',
-		'validation_logic': 'IFNULL(packed_qty, 0) < IFNULL(qty, 0)'
+		'to_field': u'item_details',
+		'to_table': u'Packing Slip Detail',
+		'validation_logic': u'IFNULL(packed_qty, 0) < IFNULL(qty, 0)'
 	}
 ]
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 4099174..b6329c5 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -24,12 +24,13 @@
 		hide_field(['customer_address','contact_person','customer_name','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']);
 	}
 
-	// defined in sales_common.js
-	//cur_frm.cscript.update_item_details(doc, cdt, cdn);
 	
 }
 
 cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
+	// defined in sales_common.js
+	//cur_frm.cscript.update_item_details(doc, cdt, cdn);
+	
 	// load default charges
 	if(doc.__islocal && !getchildren('RV Tax Detail', doc.name, 'other_charges', doc.doctype).length) 
 		cur_frm.cscript.load_taxes(doc, cdt, cdn);