Merge branch 'edge' of github.com:webnotes/erpnext into edge
diff --git a/accounts/doctype/account/account.js b/accounts/doctype/account/account.js
index 14e35d3..7738682 100644
--- a/accounts/doctype/account/account.js
+++ b/accounts/doctype/account/account.js
@@ -116,19 +116,18 @@
   });
 }
 
-// Master name get query
-// -----------------------------------------
-cur_frm.fields_dict['master_name'].get_query=function(doc){
- if (doc.master_type){
-    return 'SELECT `tab'+doc.master_type+'`.name FROM `tab'+doc.master_type+'` WHERE `tab'+doc.master_type+'`.name LIKE "%s" and `tab'+doc.master_type+'`.docstatus != 2 ORDER BY `tab'+doc.master_type+'`.name LIMIT 50';
-  }
+cur_frm.fields_dict['master_name'].get_query = function(doc) {
+	if (doc.master_type) {
+		return {
+			query: "accounts.doctype.account.account.get_master_name",
+			args: {	"master_type": doc.master_type }
+		}
+	}
 }
 
-// parent account get query
-// -----------------------------------------
-cur_frm.fields_dict['parent_account'].get_query = function(doc){
-  return 'SELECT DISTINCT `tabAccount`.name FROM `tabAccount` WHERE \
-	`tabAccount`.group_or_ledger="Group" AND `tabAccount`.docstatus != 2 AND \
-	`tabAccount`.company="'+ doc.company+'" AND `tabAccount`.company is not NULL AND \
-	`tabAccount`.name LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
+cur_frm.fields_dict['parent_account'].get_query = function(doc) {
+	return {
+		query: "accounts.doctype.account.account.get_parent_account",
+		args: { "company": doc.company}
+	}
 }
diff --git a/accounts/doctype/account/account.py b/accounts/doctype/account/account.py
index 04e13d8..14af7cf 100644
--- a/accounts/doctype/account/account.py
+++ b/accounts/doctype/account/account.py
@@ -18,15 +18,11 @@
 import webnotes
 
 from webnotes.utils import flt, fmt_money
-from webnotes.model import db_exists
-from webnotes.model.wrapper import copy_doclist
 from webnotes import msgprint
 
 sql = webnotes.conn.sql
 get_value = webnotes.conn.get_value
 
-test_records = []
-
 class DocType:
 	def __init__(self,d,dl):
 		self.doc, self.doclist = d,dl
@@ -200,4 +196,41 @@
 		sql("update `tabAccount` set account_name = '%s' where name = '%s'" % \
 			(account_name, old))
 
-		return " - ".join(parts)
\ No newline at end of file
+		return " - ".join(parts)
+
+def get_master_name(doctype, txt, searchfield, start, page_len, args):
+	return webnotes.conn.sql("""select name from `tab%s` where name like '%%%s%%'""" %
+		(args["master_type"], txt), as_list=1)
+		
+def get_parent_account(doctype, txt, searchfield, start, page_len, args):
+	return webnotes.conn.sql("""select name from tabAccount 
+		where group_or_ledger = 'Group' and docstatus != 2 and company = '%s' 
+		and name like '%%%s%%'""" % (args["company"], txt))
+
+def make_test_records(verbose):
+	from webnotes.test_runner import load_module_and_make_records, make_test_objects
+	
+	load_module_and_make_records("Company", verbose)
+	
+	accounts = [
+		# [account_name, parent_account, group_or_ledger]
+		["_Test Account Stock Expenses", "Direct Expenses - _TC", "Group"],
+		["_Test Account Shipping Charges", "_Test Account Stock Expenses - _TC", "Ledger"],
+		["_Test Account Customs Duty", "_Test Account Stock Expenses - _TC", "Ledger"],
+		["_Test Account Tax Assets", "Current Assets - _TC", "Group"],
+		["_Test Account VAT", "_Test Account Tax Assets - _TC", "Ledger"],
+		["_Test Account Cost for Goods Sold", "Expenses - _TC", "Ledger"],
+		["_Test Account Excise Duty", "_Test Account Tax Assets - _TC", "Ledger"],
+		["_Test Account Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
+		["_Test Account S&H Education Cess", "_Test Account Tax Assets - _TC", "Ledger"],
+		["_Test Account CST", "Direct Expenses - _TC", "Ledger"],
+		["_Test Account Discount", "Direct Expenses - _TC", "Ledger"]
+	]
+
+	return make_test_objects([[{
+			"doctype": "Account",
+			"account_name": account_name,
+			"parent_account": parent_account,
+			"company": "_Test Company",
+			"group_or_ledger": group_or_ledger
+		}] for account_name, parent_account, group_or_ledger in accounts])
\ No newline at end of file
diff --git a/accounts/doctype/cost_center/cost_center.py b/accounts/doctype/cost_center/cost_center.py
index d23b086..65d1f68 100644
--- a/accounts/doctype/cost_center/cost_center.py
+++ b/accounts/doctype/cost_center/cost_center.py
@@ -98,3 +98,13 @@
 			(cost_center_name, old))
 
 		return " - ".join(parts)	
+
+test_records = [
+	[{
+		"doctype": "Cost Center",
+		"cost_center_name": "_Test Cost Center",
+		"parent_cost_center": "Root - _TC",
+		"company_name": "_Test Company",
+		"group_or_ledger": "Ledger"
+	}],
+]
\ No newline at end of file
diff --git a/accounts/doctype/fiscal_year/fiscal_year.py b/accounts/doctype/fiscal_year/fiscal_year.py
index d5dff6e..3413477 100644
--- a/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/accounts/doctype/fiscal_year/fiscal_year.py
@@ -31,6 +31,11 @@
 		
 		msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
 			Please refresh your browser for the change to take effect."""))
-			
-test_records = [[{"doctype":"Fiscal Year", "year":"_Test Fiscal Year", 
-	"year_start_date":"2013-01-01"}]]
\ No newline at end of file
+
+test_records = [
+	[{
+		"doctype": "Fiscal Year", 
+		"year": "_Test Fiscal Year", 
+		"year_start_date": "2013-01-01"
+	}]
+]
\ No newline at end of file
diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py
index 4f20308..eafd7ee 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/accounts/doctype/journal_voucher/journal_voucher.py
@@ -51,7 +51,7 @@
 			self.doc.posting_date, 'Posting Date')
 		
 		self.set_against_account()
-		self.create_remarks()		
+		self.create_remarks()
 		self.set_aging_date()
 		self.set_print_format_fields()
 
@@ -152,6 +152,8 @@
 
 		if r:
 			self.doc.remark = ("\n").join(r)
+		else:
+			webnotes.msgprint("Remarks is mandatory", raise_exception=1)
 
 	def set_aging_date(self):
 		if self.doc.is_opening != 'Yes':
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py
index 98bfda5..8b65e0d 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -526,4 +526,4 @@
 
 	def on_update(self):
 		pass
-		
+
diff --git a/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index 606ebb9..8757788 100644
--- a/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -34,15 +34,15 @@
 		"group_or_ledger": "Ledger"})
 	
 	webnotes.insert({"doctype": "Account", "account_name": "Excise Duty",
-		"parent_account": "Tax Assets - %s" % abbr, "company": company,
+		"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
 		"group_or_ledger": "Ledger"})
 	
 	webnotes.insert({"doctype": "Account", "account_name": "Education Cess",
-		"parent_account": "Tax Assets - %s" % abbr, "company": company,
+		"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
 		"group_or_ledger": "Ledger"})
 	
 	webnotes.insert({"doctype": "Account", "account_name": "S&H Education Cess",
-		"parent_account": "Tax Assets - %s" % abbr, "company": company,
+		"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
 		"group_or_ledger": "Ledger"})
 		
 	webnotes.insert({"doctype": "Account", "account_name": "CST",
@@ -94,61 +94,68 @@
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "Actual",
 		"account_head": "Shipping Charges - %s" % abbr, "rate": 100, "tax_amount": 100, 
-		"category": "Valuation and Total", "parentfield": "other_charges",
-		"cost_center": "Default Cost Center - %s" % abbr
+		"category": "Valuation and Total", "parentfield": "purchase_tax_details",
+		"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Net Total",
 		"account_head": "Customs Duty - %s" % abbr, "rate": 10, "tax_amount": 125.00,
-		"category": "Valuation", "parentfield": "other_charges",
-		"cost_center": "Default Cost Center - %s" % abbr
+		"category": "Valuation", "parentfield": "purchase_tax_details",
+		"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Net Total",
 		"account_head": "Excise Duty - %s" % abbr, "rate": 12, "tax_amount": 140.00, 
-		"category": "Total", "parentfield": "other_charges"
+		"category": "Total", "parentfield": "purchase_tax_details", "add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Amount",
 		"account_head": "Education Cess - %s" % abbr, "rate": 2, "row_id": 3, "tax_amount": 2.80,
-		"category": "Total", "parentfield": "other_charges"
+		"category": "Total", "parentfield": "purchase_tax_details", "add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Amount",
 		"account_head": "S&H Education Cess - %s" % abbr, "rate": 1, "row_id": 3, 
-		"tax_amount": 1.4, "category": "Total", "parentfield": "other_charges"
+		"tax_amount": 1.4, "category": "Total", "parentfield": "purchase_tax_details",
+		"add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Total",
 		"account_head": "CST - %s" % abbr, "rate": 2, "row_id": 5, "tax_amount": 29.88, 
-		"category": "Total", "parentfield": "other_charges",
-		"cost_center": "Default Cost Center - %s" % abbr
+		"category": "Total", "parentfield": "purchase_tax_details",
+		"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Net Total",
 		"account_head": "VAT - Test - %s" % abbr, "rate": 12.5, "tax_amount": 156.25, 
-		"category": "Total", "parentfield": "other_charges"
+		"category": "Total", "parentfield": "purchase_tax_details", "add_deduct_tax": "Add"
 	},
 	{
 		"doctype": "Purchase Taxes and Charges", "charge_type": "On Previous Row Total",
-		"account_head": "Discount - %s" % abbr, "rate": -10, "row_id": 7, "tax_amount": -168.03, 
-		"category": "Total", "parentfield": "other_charges",
-		"cost_center": "Default Cost Center - %s" % abbr
+		"account_head": "Discount - %s" % abbr, "rate": 10, "row_id": 7, "tax_amount": 168.03, 
+		"category": "Total", "parentfield": "purchase_tax_details",
+		"cost_center": "Default Cost Center - %s" % abbr, "add_deduct_tax": "Deduct"
 	},
 ]
 
-class TestPurchaseReceipt(unittest.TestCase):
+class TestPurchaseInvoice(unittest.TestCase):
 	def setUp(self):
 		webnotes.conn.begin()
 		load_data()
 		# webnotes.conn.set_value("Global Defaults", None, "automatic_inventory_accounting", 1)
-			
-	def test_gl_entries(self):
-		from webnotes.model.doclist import DocList
-		controller = webnotes.insert(DocList(purchase_invoice_doclist))
-		controller.submit()
-		controller.load_from_db()
-		dl = controller.doclist
+		self.load_test_data()
+		
+	def load_test_data(self):
+		from webnotes.test_runner import make_test_records
+		make_test_records("Cost Center", verbose=0)
+		make_test_records("Item", verbose=0)
+		make_test_records("Purchase Invoice", verbose=0)
+		
+	def atest_gl_entries(self):
+		wrapper = webnotes.model_wrapper(purchase_invoice_doclist).insert()
+		wrapper.submit()
+		wrapper.load_from_db()
+		dl = wrapper.doclist
 		
 		expected_gl_entries = {
 			"East Wind Inc. - %s" % abbr : [0, 1512.30],
@@ -165,6 +172,178 @@
 			where voucher_type = 'Purchase Invoice' and voucher_no = %s""", dl[0].name, as_dict=1)
 		for d in gl_entries:
 			self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
+			
+	def test_purchase_invoice_calculation(self):
+		test_doclist = [
+			# parent
+			{
+				"doctype": "Purchase Invoice",
+				"naming_series": "BILL",
+				"supplier_name": "_Test Supplier",
+				"credit_to": "_Test Supplier - _TC",
+				"bill_no": "NA",
+				"posting_date": "2013-02-03",
+				"fiscal_year": "_Test Fiscal Year",
+				"company": "_Test Company",
+				"currency": "INR",
+				"conversion_rate": 1,
+				"grand_total_import": 0 # for feed
+			},
+			# items
+			{
+				"doctype": "Purchase Invoice Item",
+				"parentfield": "entries",
+				"item_code": "_Test Item Home Desktop 100",
+				"item_name": "_Test Item Home Desktop 100",
+				"qty": 10,
+				"import_rate": 50,
+				"import_amount": 500,
+				"rate": 50,
+				"amount": 50,
+				"uom": "_Test UOM",
+				"item_tax_rate": json.dumps({"_Test Account Excise Duty - _TC": 10}),
+				"expense_head": "_Test Account Cost for Goods Sold - _TC",
+				"cost_center": "_Test Cost Center - _TC"
+				
+			},
+			{
+				"doctype": "Purchase Invoice Item",
+				"parentfield": "entries",
+				"item_code": "_Test Item Home Desktop 200",
+				"item_name": "_Test Item Home Desktop 200",
+				"qty": 5,
+				"import_rate": 150,
+				"import_amount": 750,
+				"rate": 150,
+				"amount": 750,
+				"uom": "_Test UOM",
+				"expense_head": "_Test Account Cost for Goods Sold - _TC",
+				"cost_center": "_Test Cost Center - _TC"
+			},
+			# taxes
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "Actual",
+				"account_head": "_Test Account Shipping Charges - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "Shipping Charges",
+				"category": "Valuation and Total",
+				"add_deduct_tax": "Add",
+				"rate": 100
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Net Total",
+				"account_head": "_Test Account Customs Duty - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "Customs Duty",
+				"category": "Valuation",
+				"add_deduct_tax": "Add",
+				"rate": 10
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Net Total",
+				"account_head": "_Test Account Excise Duty - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "Excise Duty",
+				"category": "Total",
+				"add_deduct_tax": "Add",
+				"rate": 12
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Previous Row Amount",
+				"account_head": "_Test Account Education Cess - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "Education Cess",
+				"category": "Total",
+				"add_deduct_tax": "Add",
+				"rate": 2,
+				"row_id": 3
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Previous Row Amount",
+				"account_head": "_Test Account S&H Education Cess - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "S&H Education Cess",
+				"category": "Total",
+				"add_deduct_tax": "Add",
+				"rate": 1,
+				"row_id": 3
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Previous Row Total",
+				"account_head": "_Test Account CST - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "CST",
+				"category": "Total",
+				"add_deduct_tax": "Add",
+				"rate": 2,
+				"row_id": 5
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Net Total",
+				"account_head": "_Test Account VAT - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "VAT",
+				"category": "Total",
+				"add_deduct_tax": "Add",
+				"rate": 12.5
+			},
+			{
+				"doctype": "Purchase Taxes and Charges",
+				"parentfield": "purchase_tax_details",
+				"charge_type": "On Previous Row Total",
+				"account_head": "_Test Account Discount - _TC",
+				"cost_center": "_Test Cost Center - _TC",
+				"description": "Discount",
+				"category": "Total",
+				"add_deduct_tax": "Deduct",
+				"rate": 10,
+				"row_id": 7
+			},
+		]
+				
+		wrapper = webnotes.model_wrapper(test_doclist).insert()
+		wrapper.load_from_db()
+		
+		# tax amounts
+		expected_values = [
+			["_Test Account Shipping Charges - _TC", 100, 1350],
+			["_Test Account Customs Duty - _TC", 125, 1350],
+			["_Test Account Excise Duty - _TC", 140, 1490],
+			["_Test Account Education Cess - _TC", 2.8, 1492.8],
+			["_Test Account S&H Education Cess - _TC", 1.4, 1494.2],
+			["_Test Account CST - _TC", 29.88, 1524.08],
+			["_Test Account VAT - _TC", 156.25, 1680.33],
+			["_Test Account Discount - _TC", 168.03, 1512.30],
+		]
+		
+		for i, tax in enumerate(wrapper.doclist.get({"parentfield": "purchase_tax_details"})):
+			self.assertEqual(tax.account_head, expected_values[i][0])
+			self.assertEqual(tax.tax_amount, expected_values[i][1])
+			self.assertEqual(tax.total, expected_values[i][2])
+
+		expected_values = [
+			["_Test Item Home Desktop 100", 90],
+			["_Test Item Home Desktop 200", 135]
+		]
+		for i, item in enumerate(wrapper.doclist.get({"parentfield": "entries"})):
+			self.assertEqual(item.item_code, expected_values[i][0])
+			self.assertEqual(item.item_tax_amount, expected_values[i][1])
+			
+		# self.assertEqual(dl[0].net_total, 1250)
 
 	def tearDown(self):
 		webnotes.conn.rollback()
\ No newline at end of file
diff --git a/accounts/doctype/sales_invoice/test_sales_invoice.py b/accounts/doctype/sales_invoice/test_sales_invoice.py
index bb2157c..06ca887 100644
--- a/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -32,16 +32,16 @@
 	
 	# create customer group
 	webnotes.insert({"doctype": "Customer Group",
-		"customer_group_name": "Default Customer Group",
+		"customer_group_name": "_Test Customer Group",
 		"parent_customer_group": "All Customer Groups", "is_group": "No"})
 	
 	# create customer
 	webnotes.insert({"doctype": "Customer", "customer_name": "West Wind Inc.",
 		"customer_type": "Company", "territory": "Default",
-		"customer_group": "Default Customer Group", "company": company,
+		"customer_group": "_Test Customer Group", "company": company,
 		"credit_days": 50, "credit_limit": 0})
 	
-	webnotes.insert({"doctype": "Account", "account_name": "Sales",
+	webnotes.insert({"doctype": "Account", "account_name": "_Test Account Sales",
 		"parent_account": "Income - %s" % abbr, "company": company,
 		"group_or_ledger": "Ledger"})
 	
@@ -93,15 +93,15 @@
 		"doctype": "Sales Invoice Item", "warehouse": "Default Warehouse",
 		"item_code": "Home Desktop 100", "qty": 10, "basic_rate": 50, "amount": 500, 
 		"parentfield": "entries", "so_detail": None, "dn_detail": None,
-		"uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}),
-		"income_account": "Sales - %s" % abbr, 
+		"stock_uom": "Nos", "item_tax_rate": json.dumps({"Excise Duty - %s" % abbr: 10}),
+		"income_account": "_Test Account Sales - %s" % abbr, 
 		"cost_center": "Default Cost Center - %s" % abbr
 	},
 	{
 		"doctype": "Sales Invoice Item", "warehouse": "Default Warehouse",
 		"item_code": "Home Desktop 200", "qty": 5, "basic_rate": 150, "amount": 750,
 		"so_detail": None, "dn_detail": None, 
-		"parentfield": "entries", "uom": "Nos", "income_account": "Sales - %s" % abbr, 
+		"parentfield": "entries", "stock_uom": "Nos", "income_account": "_Test Account Sales - %s" % abbr, 
 		"cost_center": "Default Cost Center - %s" % abbr
 	},
 	# taxes
@@ -211,7 +211,7 @@
 			
 		expected_gl_entries = {
 			"West Wind Inc. - %s" % abbr : [1627.05, 0.0],
-			"Sales - %s" % abbr: [0.0, 1250.00],
+			"_Test Account Sales - %s" % abbr: [0.0, 1250.00],
 			"Shipping Charges - %s" % abbr: [0.0, 100],
 			"Customs Duty - %s" % abbr: [0, 125.0],
 			"Excise Duty - %s" % abbr: [0, 140],
diff --git a/accounts/page/voucher_import_tool/voucher_import_tool.py b/accounts/page/voucher_import_tool/voucher_import_tool.py
index 0d3a7f7..f99a078 100644
--- a/accounts/page/voucher_import_tool/voucher_import_tool.py
+++ b/accounts/page/voucher_import_tool/voucher_import_tool.py
@@ -168,7 +168,7 @@
 		webnotes.conn.commit()
 	except Exception, e:
 		webnotes.conn.rollback()
-		err_msg = webnotes.message_log and webnotes.message_log[0] or unicode(e)
+		err_msg = webnotes.message_log and "<br>".join(webnotes.message_log) or unicode(e)
 		messages.append("""<p style='color: red'>[row #%s] %s failed: %s</p>"""
 			% ((start_idx + 1) + i, jv.name or "", err_msg or "No message"))
 		messages.append("<p style='color: red'>All transactions rolled back</p>")
diff --git a/buying/doctype/purchase_order_item/purchase_order_item.txt b/buying/doctype/purchase_order_item/purchase_order_item.txt
index 20ba876..c8c21ca 100755
--- a/buying/doctype/purchase_order_item/purchase_order_item.txt
+++ b/buying/doctype/purchase_order_item/purchase_order_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-28 10:05:59", 
+  "creation": "2013-01-30 12:49:48", 
   "docstatus": 0, 
-  "modified": "2013-01-29 16:28:05", 
+  "modified": "2013-02-07 10:49:35", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -344,7 +344,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "print_width": "100px", 
-  "read_only": 1, 
+  "read_only": 0, 
   "width": "100px"
  }, 
  {
diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py
index 096a43e..0149f81 100644
--- a/buying/doctype/supplier/supplier.py
+++ b/buying/doctype/supplier/supplier.py
@@ -182,3 +182,12 @@
 		#update master_name in doctype account
 		webnotes.conn.sql("""update `tabAccount` set master_name = %s, 
 			master_type = 'Supplier' where master_name = %s""" , (new,old))
+
+test_records = [
+	[{
+		"doctype": "Supplier",
+		"supplier_name": "_Test Supplier",
+		"supplier_type": "_Test Supplier Type",
+		"company": "_Test Company"
+	}]
+]
\ No newline at end of file
diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py
index a80afc5..60535cc 100644
--- a/controllers/accounts_controller.py
+++ b/controllers/accounts_controller.py
@@ -17,7 +17,6 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import flt
-from webnotes.model.doc import addchild
 from utilities.transaction_base import TransactionBase
 
 class AccountsController(TransactionBase):
@@ -47,15 +46,13 @@
 		
 		return stock_in_hand
 		
-	def clear_unallocated_advances(self, parenttype, parentfield):
-		for d in self.doclist:
-			if d.parentfield == parentfield and flt(d.allocated_amount) == 0:
-				self.doclist.remove(d)
+	def clear_unallocated_advances(self, childtype, parentfield):
+		self.doclist.remove_items({"parentfield": parentfield, "allocated_amount": ["in", [0, None, ""]]})
 			
-		webnotes.conn.sql("""delete from `tab%s` where parent = %s 
-			and ifnull(allocated_amount, 0) = 0""" % (parenttype, '%s'), self.doc.name)			
+		webnotes.conn.sql("""delete from `tab%s` where parentfield=%s and parent = %s 
+			and ifnull(allocated_amount, 0) = 0""" % (childtype, '%s', '%s'), (parentfield, self.doc.name))
 		
-	def get_advances(self, account_head, parenttype, parentfield, dr_or_cr):
+	def get_advances(self, account_head, child_doctype, parentfield, dr_or_cr):
 		res = webnotes.conn.sql("""select t1.name as jv_no, t1.remark, 
 			t2.%s as amount, t2.name as jv_detail_no
 			from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 
@@ -68,9 +65,12 @@
 			
 		self.doclist = self.doc.clear_table(self.doclist, parentfield)
 		for d in res:
-			add = addchild(self.doc, parentfield, parenttype, self.doclist)
-			add.journal_voucher = d.jv_no
-			add.jv_detail_no = d.jv_detail_no
-			add.remarks = d.remark
-			add.advance_amount = flt(d.amount)
-			add.allocate_amount = 0
\ No newline at end of file
+			self.doclist.append({
+				"doctype": child_doctype,
+				"parentfield": parentfield,
+				"journal_voucher": d.jv_no,
+				"jv_detail_no": d.jv_detail_no,
+				"remarks": d.remark,
+				"advance_amount": flt(d.amount),
+				"allocate_amount": 0
+			})
\ No newline at end of file
diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py
index 8a51e3a..511ca17 100644
--- a/controllers/buying_controller.py
+++ b/controllers/buying_controller.py
@@ -83,4 +83,15 @@
 			self.doc.in_words = money_in_words(self.doc.grand_total, company_currency)
 		if self.meta.get_field("in_words_import"):
 			self.doc.in_words_import = money_in_words(self.doc.grand_total_import,
-		 		self.doc.currency)
\ No newline at end of file
+		 		self.doc.currency)
+		
+	def calculate_taxes_and_totals(self):
+		self.doc.conversion_rate = flt(self.doc.conversion_rate)
+		
+		# self.calculate_item_values()
+		# self.initialize_taxes()
+		# self.calculate_net_total()
+		# self.calculate_taxes()
+		# self.calculate_totals()
+		# self.set_total_in_words()
+		
\ No newline at end of file
diff --git a/hr/doctype/appraisal/appraisal.py b/hr/doctype/appraisal/appraisal.py
index 849e48a..3d49c31 100644
--- a/hr/doctype/appraisal/appraisal.py
+++ b/hr/doctype/appraisal/appraisal.py
@@ -77,10 +77,9 @@
 			msgprint("Total weightage assigned should be 100%. It is :" + str(total_w) + "%", 
 				raise_exception=1)
 
-		if webnotes.conn.get_default("employee", webnotes.session.user) != self.doc.employee:
-		
-			if total==0:
-				msgprint("Total can't be zero. You must atleast give some points!", raise_exception=1)
+		if webnotes.conn.get_value("Employee", self.doc.employee, "user_id") != \
+				webnotes.session.user and total == 0:
+			msgprint("Total can't be zero. You must atleast give some points!", raise_exception=1)
 
 		self.doc.total_score = total
 			
diff --git a/hr/doctype/employee/employee.txt b/hr/doctype/employee/employee.txt
index e8879f5..7b1f730 100644
--- a/hr/doctype/employee/employee.txt
+++ b/hr/doctype/employee/employee.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-23 19:57:17", 
   "docstatus": 0, 
-  "modified": "2013-01-29 17:47:25", 
+  "modified": "2013-02-08 13:07:25", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -545,14 +545,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "salary_structure", 
-  "fieldtype": "Button", 
-  "hidden": 1, 
-  "label": "Salary Structure", 
-  "oldfieldtype": "Button"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "place_of_issue", 
   "fieldtype": "Data", 
   "label": "Place of Issue"
@@ -775,4 +767,4 @@
   "role": "HR Manager", 
   "write": 1
  }
-]
\ No newline at end of file
+]
diff --git a/hr/doctype/holiday_block_list/holiday_block_list.py b/hr/doctype/holiday_block_list/holiday_block_list.py
index 619f373..87ab705 100644
--- a/hr/doctype/holiday_block_list/holiday_block_list.py
+++ b/hr/doctype/holiday_block_list/holiday_block_list.py
@@ -23,7 +23,8 @@
 test_records = [[{
 		"doctype":"Holiday Block List",
 		"holiday_block_list_name": "_Test Holiday Block List",
-		"year": "_Test Fiscal Year"
+		"year": "_Test Fiscal Year",
+		"company": "_Test Company"
 	}, {
 		"doctype": "Holiday Block List Date",
 		"parent": "_Test Holiday Block List",
diff --git a/hr/doctype/holiday_block_list/holiday_block_list.txt b/hr/doctype/holiday_block_list/holiday_block_list.txt
index 31b2f98..23b70e2 100644
--- a/hr/doctype/holiday_block_list/holiday_block_list.txt
+++ b/hr/doctype/holiday_block_list/holiday_block_list.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-02-04 15:31:29", 
   "docstatus": 0, 
-  "modified": "2013-02-06 14:39:09", 
+  "modified": "2013-02-07 08:47:25", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -54,6 +54,21 @@
   "reqd": 1
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "company", 
+  "fieldtype": "Link", 
+  "label": "Company", 
+  "options": "Company", 
+  "reqd": 1
+ }, 
+ {
+  "description": "If not checked, the list will have to be added to each Department where it has to be applied.", 
+  "doctype": "DocField", 
+  "fieldname": "applies_to_all_departments", 
+  "fieldtype": "Check", 
+  "label": "Applies to all Departments"
+ }, 
+ {
   "description": "Stop users from making Leave Applications on following days.", 
   "doctype": "DocField", 
   "fieldname": "block_days", 
diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py
index cab8f17..9c6278d 100755
--- a/hr/doctype/leave_application/leave_application.py
+++ b/hr/doctype/leave_application/leave_application.py
@@ -46,22 +46,39 @@
 				raise_exception=True)
 
 	def validate_block_days(self):
-		from_date = getdate(self.doc.from_date)
-		to_date = getdate(self.doc.to_date)
-		
+		for block_list in self.get_applicable_block_lists():
+			self.check_block_dates(block_list)
+
+	def get_applicable_block_lists(self):
+		block_lists = []
+		def add_block_list(block_list):
+			if block_list:
+				if not self.is_user_in_allow_list(block_list):
+					block_lists.append(block_list)
+
+		# per department
 		department = webnotes.conn.get_value("Employee", self.doc.employee, "department")
 		if department:
 			block_list = webnotes.conn.get_value("Department", department, "holiday_block_list")
-			if block_list:
-				if self.is_user_in_allow_list(block_list):
-					return
-				for d in webnotes.conn.sql("""select block_date, reason from
-					`tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1):
-					block_date = getdate(d.block_date)
-					if block_date > from_date and block_date < to_date:
-						webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
-							+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
-						raise LeaveDayBlockedError
+			add_block_list(block_list)
+
+		# global
+		for block_list in webnotes.conn.sql_list("""select name from `tabHoliday Block List`
+			where ifnull(applies_to_all_departments,0)=1 and company=%s""", self.doc.company):
+			add_block_list(block_list)
+				
+		return block_lists
+
+	def check_block_dates(self, block_list):
+		from_date = getdate(self.doc.from_date)
+		to_date = getdate(self.doc.to_date)
+		for d in webnotes.conn.sql("""select block_date, reason from
+			`tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1):
+			block_date = getdate(d.block_date)
+			if block_date > from_date and block_date < to_date:
+				webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
+					+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
+				raise LeaveDayBlockedError
 
 	def is_user_in_allow_list(self, block_list):
 		return webnotes.session.user in webnotes.conn.sql_list("""select allow_user
diff --git a/hr/doctype/leave_application/leave_application.txt b/hr/doctype/leave_application/leave_application.txt
index 4436d3c..ec17544 100644
--- a/hr/doctype/leave_application/leave_application.txt
+++ b/hr/doctype/leave_application/leave_application.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-10 16:34:14", 
+  "creation": "2013-02-02 14:40:08", 
   "docstatus": 0, 
-  "modified": "2013-02-01 10:34:14", 
+  "modified": "2013-02-08 11:27:22", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -165,7 +165,7 @@
   "fieldtype": "Date", 
   "label": "Posting Date", 
   "no_copy": 1, 
-  "permlevel": 2, 
+  "permlevel": 0, 
   "reqd": 1
  }, 
  {
@@ -175,18 +175,27 @@
   "in_filter": 1, 
   "label": "Fiscal Year", 
   "options": "link:Fiscal Year", 
-  "permlevel": 2, 
+  "permlevel": 0, 
   "read_only": 0, 
   "reqd": 1, 
   "search_index": 0
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "company", 
+  "fieldtype": "Link", 
+  "label": "Company", 
+  "options": "Company", 
+  "permlevel": 0, 
+  "reqd": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "letter_head", 
   "fieldtype": "Link", 
   "label": "Letter Head", 
   "options": "Letter Head", 
-  "permlevel": 2, 
+  "permlevel": 0, 
   "print_hide": 1, 
   "read_only": 0
  }, 
diff --git a/hr/doctype/leave_application/test_leave_application.py b/hr/doctype/leave_application/test_leave_application.py
index e485289..22164a7 100644
--- a/hr/doctype/leave_application/test_leave_application.py
+++ b/hr/doctype/leave_application/test_leave_application.py
@@ -1,23 +1,39 @@
 import sys
 import unittest
 
+if __name__=="__main__":
+	sys.path.extend([".", "app", "lib"])
+
 from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
 
 class TestLeaveApplication(unittest.TestCase):
+	def get_application(self):
+		application = webnotes.model_wrapper(test_records[1])
+		application.doc.from_date = "2013-01-01"
+		application.doc.to_date = "2013-01-05"
+		return application
+
 	def test_block_list(self):
 		import webnotes
 		webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", 
 			"_Test Department with Block List")
 		
-		application = webnotes.model_wrapper(test_records[1])
-		application.doc.from_date = "2013-01-01"
-		application.doc.to_date = "2013-01-05"
+		application = self.get_application()
 		self.assertRaises(LeaveDayBlockedError, application.insert)
 		
 		webnotes.session.user = "test1@erpnext.com"
 		webnotes.get_obj("Profile", "test1@erpnext.com").add_role("HR User")
 		self.assertTrue(application.insert())
 		
+	def test_global_block_list(self):
+		application = self.get_application()
+		webnotes.conn.set_value("Holiday Block List", "_Test Holiday Block List", 
+			"applies_to_all_departments", 1)
+		webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", 
+			"_Test Department")
+		webnotes.session.user = "test@erpnext.com"
+
+		self.assertRaises(LeaveDayBlockedError, application.insert)
 
 test_records = [
 	[{
@@ -35,11 +51,11 @@
 		"to_date": "2013-05-05",
 		"posting_date": "2013-01-02",
 		"fiscal_year": "_Test Fiscal Year",
-		"employee": "_T-Employee-0001"
+		"employee": "_T-Employee-0001",
+		"company": "_Test Company"
 	}]]
 
 if __name__=="__main__":
-	sys.path.extend(["app", "lib"])
 	import webnotes
 	webnotes.connect()
 
diff --git a/patches/february_2013/update_company_in_leave_application.py b/patches/february_2013/update_company_in_leave_application.py
new file mode 100644
index 0000000..be07cb8
--- /dev/null
+++ b/patches/february_2013/update_company_in_leave_application.py
@@ -0,0 +1,12 @@
+def execute():
+	import webnotes
+	webnotes.reload_doc("hr", "doctype", "leave_application")
+	
+	webnotes.conn.sql("""update `tabLeave Application`, `tabEmployee` set
+		`tabLeave Application`.company = `tabEmployee`.company where
+		`tabLeave Application`.employee = `tabEmployee`.name""")
+		
+	company = webnotes.conn.get_default("company")
+	if company:
+		webnotes.conn.sql("""update `tabLeave Application`
+			set company = %s where ifnull(company,'')=''""", company)
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index cf9c189..467c6b0 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -166,4 +166,5 @@
 	"patches.february_2013.remove_sales_order_pending_items",
 	"patches.february_2013.account_negative_balance",
 	"patches.february_2013.remove_account_utils_folder",
+	"patches.february_2013.update_company_in_leave_application"
 ]
\ No newline at end of file
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index 01fa69c..932256f 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -249,3 +249,14 @@
 		#update master_name in doctype account
 		webnotes.conn.sql("""update `tabAccount` set master_name = %s, 
 			master_type = 'Customer' where master_name = %s""", (new,old))
+
+test_records = [
+	[{
+		"doctype": "Customer",
+		"customer_name": "_Test Customer",
+		"customer_type": "Individual",
+		"customer_group": "_Test Customer Group",
+		"territory": "_Test Territory",
+		"company": "_Test Company"
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/brand/brand.py b/setup/doctype/brand/brand.py
index 7f48feb..19546da 100644
--- a/setup/doctype/brand/brand.py
+++ b/setup/doctype/brand/brand.py
@@ -19,4 +19,11 @@
 
 class DocType:
 	def __init__(self, d, dl):
-		self.doc, self.doclist = d, dl
\ No newline at end of file
+		self.doc, self.doclist = d, dl
+		
+test_records = [
+	[{
+		"doctype": "Brand",
+		"brand": "_Test Brand"
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index b36253e..a951af5 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -258,9 +258,9 @@
 
 test_records = [
 	[{
+		"doctype": "Company",
 		"company_name": "_Test Company",
-		"abbr": "TC",
+		"abbr": "_TC",
 		"default_currency": "INR",
-		"doctype": "Company"
-	}]
+	}],
 ]
\ No newline at end of file
diff --git a/setup/doctype/country/country.py b/setup/doctype/country/country.py
index 7f48feb..360f679 100644
--- a/setup/doctype/country/country.py
+++ b/setup/doctype/country/country.py
@@ -19,4 +19,11 @@
 
 class DocType:
 	def __init__(self, d, dl):
-		self.doc, self.doclist = d, dl
\ No newline at end of file
+		self.doc, self.doclist = d, dl
+		
+test_records = [
+	[{
+		"doctype": "Country",
+		"country_name": "_Test Country"
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/currency/currency.py b/setup/doctype/currency/currency.py
index 73076cb..7794430 100644
--- a/setup/doctype/currency/currency.py
+++ b/setup/doctype/currency/currency.py
@@ -20,5 +20,3 @@
 class DocType:
 	def __init__(self, d, dl):
 		self.doc, self.doclist = d, dl
-		
-test_records = []
\ No newline at end of file
diff --git a/setup/doctype/customer_group/customer_group.py b/setup/doctype/customer_group/customer_group.py
index b34d3c6..fa81dca 100644
--- a/setup/doctype/customer_group/customer_group.py
+++ b/setup/doctype/customer_group/customer_group.py
@@ -16,9 +16,6 @@
 
 from __future__ import unicode_literals
 import webnotes
-
-from webnotes.model import db_exists
-from webnotes.model.wrapper import copy_doclist
 from webnotes import msgprint
 
 sql = webnotes.conn.sql
@@ -63,4 +60,13 @@
 				You can not trash/cancel/delete this customer group.", raise_exception=1)
 
 		# rebuild tree
-		super(DocType, self).on_trash()
\ No newline at end of file
+		super(DocType, self).on_trash()
+
+test_records = [
+	[{
+		"doctype": "Customer Group",
+		"customer_group_name": "_Test Customer Group",
+		"parent_customer_group": "All Customer Groups",
+		"is_group": "No"
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/item_group/item_group.py b/setup/doctype/item_group/item_group.py
index 32c5d52..c0fd906 100644
--- a/setup/doctype/item_group/item_group.py
+++ b/setup/doctype/item_group/item_group.py
@@ -67,4 +67,19 @@
 
 		if self.doc.slideshow:
 			from website.helpers.slideshow import get_slideshow
-			get_slideshow(self)
\ No newline at end of file
+			get_slideshow(self)
+			
+test_records = [
+	[{
+		"doctype": "Item Group",
+		"item_group_name": "_Test Item Group",
+		"parent_item_group": "All Item Groups",
+		"is_group": "No"
+	}],
+	[{
+		"doctype": "Item Group",
+		"item_group_name": "_Test Item Group Desktops",
+		"parent_item_group": "All Item Groups",
+		"is_group": "No"
+	}],
+]
\ No newline at end of file
diff --git a/setup/doctype/supplier_type/supplier_type.py b/setup/doctype/supplier_type/supplier_type.py
index 7f48feb..4a8fdff 100644
--- a/setup/doctype/supplier_type/supplier_type.py
+++ b/setup/doctype/supplier_type/supplier_type.py
@@ -19,4 +19,12 @@
 
 class DocType:
 	def __init__(self, d, dl):
-		self.doc, self.doclist = d, dl
\ No newline at end of file
+		self.doc, self.doclist = d, dl
+		
+
+test_records = [
+	[{
+		"doctype": "Supplier Type",
+		"supplier_type": "_Test Supplier Type",
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/territory/territory.py b/setup/doctype/territory/territory.py
index 6d2da6a..11bd4cc 100644
--- a/setup/doctype/territory/territory.py
+++ b/setup/doctype/territory/territory.py
@@ -32,4 +32,13 @@
 		for d in getlist(self.doclist, 'target_details'):
 			if not flt(d.target_qty) and not flt(d.target_amount):
 				msgprint("Either target qty or target amount is mandatory.")
-				raise Exception		
\ No newline at end of file
+				raise Exception
+				
+test_records = [
+	[{
+		"doctype": "Territory",
+		"territory_name": "_Test Territory",
+		"parent_territory": "All Territories",
+		"is_group": "No",
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/uom/uom.py b/setup/doctype/uom/uom.py
index 7f48feb..733cb57 100644
--- a/setup/doctype/uom/uom.py
+++ b/setup/doctype/uom/uom.py
@@ -19,4 +19,11 @@
 
 class DocType:
 	def __init__(self, d, dl):
-		self.doc, self.doclist = d, dl
\ No newline at end of file
+		self.doc, self.doclist = d, dl
+		
+test_records = [
+	[{
+		"doctype": "UOM",
+		"uom_name": "_Test UOM"
+	}]
+]
\ No newline at end of file
diff --git a/setup/doctype/warehouse_type/warehouse_type.py b/setup/doctype/warehouse_type/warehouse_type.py
index 7f48feb..451db41 100644
--- a/setup/doctype/warehouse_type/warehouse_type.py
+++ b/setup/doctype/warehouse_type/warehouse_type.py
@@ -19,4 +19,11 @@
 
 class DocType:
 	def __init__(self, d, dl):
-		self.doc, self.doclist = d, dl
\ No newline at end of file
+		self.doc, self.doclist = d, dl
+		
+test_records = [
+	[{
+		"doctype": "Warehouse Type",
+		"warehouse_type": "_Test Warehouse Type"
+	}]
+]
\ No newline at end of file
diff --git a/startup/report_data_map.py b/startup/report_data_map.py
index dc1833d..ff9f3e4 100644
--- a/startup/report_data_map.py
+++ b/startup/report_data_map.py
@@ -47,7 +47,7 @@
 		"order_by": "lft"
 	},
 	"GL Entry": {
-		"columns": ["account", "posting_date", "cost_center", "debit", "credit", "is_opening",
+		"columns": ["name", "account", "posting_date", "cost_center", "debit", "credit", "is_opening",
 			"company", "voucher_type", "voucher_no", "remarks"],
 		"conditions": ["ifnull(is_cancelled, 'No')='No'"],
 		"order_by": "posting_date, account",
@@ -86,7 +86,7 @@
 		"order_by": "name"
 	},
 	"Stock Ledger Entry": {
-		"columns": ["posting_date", "posting_time", "item_code", "warehouse", "actual_qty as qty",
+		"columns": ["name", "posting_date", "posting_time", "item_code", "warehouse", "actual_qty as qty",
 			"voucher_type", "voucher_no", "ifnull(incoming_rate,0) as incoming_rate"],
 		"conditions": ["ifnull(is_cancelled, 'No')='No'"],
 		"order_by": "posting_date, posting_time, name",
@@ -102,7 +102,7 @@
 		"order_by": "posting_date, posting_time, name",
 	},
 	"Production Order": {
-		"columns": ["production_item as item_code", 
+		"columns": ["name", "production_item as item_code", 
 			"(ifnull(qty, 0) - ifnull(produced_qty, 0)) as qty", 
 			"fg_warehouse as warehouse"],
 		"conditions": ["docstatus=1", "status != 'Stopped'", "ifnull(fg_warehouse, '')!=''",
@@ -113,7 +113,7 @@
 		},
 	},
 	"Purchase Request Item": {
-		"columns": ["item_code", "warehouse", 
+		"columns": ["name", "item_code", "warehouse", 
 			"(ifnull(qty, 0) - ifnull(ordered_qty, 0)) as qty"],
 		"from": "`tabPurchase Request Item` item, `tabPurchase Request` main",
 		"conditions": ["item.parent = main.name", "main.docstatus=1", "main.status != 'Stopped'", 
@@ -124,7 +124,7 @@
 		},
 	},
 	"Purchase Order Item": {
-		"columns": ["item_code", "warehouse", 
+		"columns": ["name", "item_code", "warehouse", 
 			"(ifnull(qty, 0) - ifnull(received_qty, 0)) as qty"],
 		"from": "`tabPurchase Order Item` item, `tabPurchase Order` main",
 		"conditions": ["item.parent = main.name", "main.docstatus=1", "main.status != 'Stopped'", 
@@ -136,7 +136,7 @@
 	},
 	
 	"Sales Order Item": {
-		"columns": ["item_code", "(ifnull(qty, 0) - ifnull(delivered_qty, 0)) as qty", 
+		"columns": ["name", "item_code", "(ifnull(qty, 0) - ifnull(delivered_qty, 0)) as qty", 
 			"reserved_warehouse as warehouse"],
 		"from": "`tabSales Order Item` item, `tabSales Order` main",
 		"conditions": ["item.parent = main.name", "main.docstatus=1", "main.status != 'Stopped'", 
@@ -178,7 +178,7 @@
 		}
 	},
 	"Sales Invoice Item": {
-		"columns": ["parent", "item_code", "qty", "amount"],
+		"columns": ["name", "parent", "item_code", "qty", "amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -196,7 +196,7 @@
 		}
 	},
 	"Sales Order Item[Sales Analytics]": {
-		"columns": ["parent", "item_code", "qty", "amount"],
+		"columns": ["name", "parent", "item_code", "qty", "amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -214,7 +214,7 @@
 		}
 	},
 	"Delivery Note Item[Sales Analytics]": {
-		"columns": ["parent", "item_code", "qty", "amount"],
+		"columns": ["name", "parent", "item_code", "qty", "amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -246,7 +246,7 @@
 		}
 	},
 	"Purchase Invoice Item": {
-		"columns": ["parent", "item_code", "qty", "amount"],
+		"columns": ["name", "parent", "item_code", "qty", "amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -264,7 +264,7 @@
 		}
 	},
 	"Purchase Order Item[Purchase Analytics]": {
-		"columns": ["parent", "item_code", "qty", "amount"],
+		"columns": ["name", "parent", "item_code", "qty", "amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
@@ -282,7 +282,7 @@
 		}
 	},
 	"Purchase Receipt Item[Purchase Analytics]": {
-		"columns": ["parent", "item_code", "qty", "amount"],
+		"columns": ["name", "parent", "item_code", "qty", "amount"],
 		"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
 		"order_by": "parent",
 		"links": {
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index eab977b..2d781bd 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -122,21 +122,20 @@
 			cust_code.append(d.ref_code)
 		self.doc.customer_code=','.join(cust_code)
 
-	# Check whether Tax Rate is not entered twice for same Tax Type
 	def check_item_tax(self):
+		"""Check whether Tax Rate is not entered twice for same Tax Type"""
 		check_list=[]
 		for d in getlist(self.doclist,'item_tax'):
-			account_type = sql("select account_type from tabAccount where name = %s",d.tax_type)
-			account_type = account_type and account_type[0][0] or ''
-			if account_type not in ['Tax', 'Chargeable']:
-				msgprint("'%s' is not Tax / Chargeable Account"%(d.tax_type))
-				raise Exception, "Tax Account validation"
-			else:
-				if d.tax_type in check_list:
-					msgprint("Rate is entered twice for Tax : '%s'." % (d.tax_type))
-					raise Exception
+			if d.tax_type:
+				account_type = webnotes.conn.get_value("Account", d.tax_type, "account_type")
+				
+				if account_type not in ['Tax', 'Chargeable']:
+					msgprint("'%s' is not Tax / Chargeable Account" % d.tax_type, raise_exception=1)
 				else:
-					check_list.append(d.tax_type)
+					if d.tax_type in check_list:
+						msgprint("Rate is entered twice for: '%s'" % d.tax_type, raise_exception=1)
+					else:
+						check_list.append(d.tax_type)
 
 	def check_for_active_boms(self, field_label):
 		if field_label in ['Is Active', 'Is Purchase Item']:
@@ -221,4 +220,50 @@
 
 		if self.doc.slideshow:
 			from website.helpers.slideshow import get_slideshow
-			get_slideshow(self)
\ No newline at end of file
+			get_slideshow(self)
+			
+test_records = [
+	[{
+		"doctype": "Item",
+		"item_code": "_Test Item Home Desktop 100",
+		"item_name": "_Test Item Home Desktop 100",
+		"description": "_Test Item Home Desktop 100",
+		"item_group": "_Test Item Group Desktops",
+		"is_stock_item": "Yes",
+		"is_asset_item": "No",
+		"has_batch_no": "No",
+		"has_serial_no": "No",
+		"is_purchase_item": "Yes",
+		"is_sales_item": "Yes",
+		"is_service_item": "No",
+		"is_sample_item": "No",
+		"inspection_required": "No",
+		"is_pro_applicable": "No",
+		"is_sub_contracted_item": "No",
+		"stock_uom": "_Test UOM"
+	},
+	{
+		"doctype": "Item Tax",
+		"tax_type": "_Test Account Excise Duty - _TC",
+		"tax_rate": 10
+	}],
+	[{
+		"doctype": "Item",
+		"item_code": "_Test Item Home Desktop 200",
+		"item_name": "_Test Item Home Desktop 200",
+		"description": "_Test Item Home Desktop 200",
+		"item_group": "_Test Item Group Desktops",
+		"is_stock_item": "Yes",
+		"is_asset_item": "No",
+		"has_batch_no": "No",
+		"has_serial_no": "No",
+		"is_purchase_item": "Yes",
+		"is_sales_item": "Yes",
+		"is_service_item": "No",
+		"is_sample_item": "No",
+		"inspection_required": "No",
+		"is_pro_applicable": "No",
+		"is_sub_contracted_item": "No",
+		"stock_uom": "_Test UOM"
+	}],
+]
\ No newline at end of file
diff --git a/stock/doctype/purchase_receipt/test_purchase_receipt.py b/stock/doctype/purchase_receipt/test_purchase_receipt.py
index b619cbd..f91455f 100644
--- a/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -56,7 +56,7 @@
 		webnotes.insert({"doctype": "Cost Center", "group_or_ledger": "Ledger",
 			"cost_center_name": "Default Cost Center", 
 			"parent_cost_center": "Root - %s" % abbr,
-			"company_name": company, "company_abbr": abbr})
+			"company_name": company})
 		
 	# create account heads for taxes
 	
@@ -67,11 +67,11 @@
 	webnotes.insert({"doctype": "Account", "account_name": "Customs Duty",
 		"parent_account": "Stock Expenses - %s" % abbr, "company": company,
 		"group_or_ledger": "Ledger"})
-	webnotes.insert({"doctype": "Account", "account_name": "Tax Assets",
+	webnotes.insert({"doctype": "Account", "account_name": "_Test Tax Assets",
 		"parent_account": "Current Assets - %s" % abbr, "company": company,
 		"group_or_ledger": "Group"})
 	webnotes.insert({"doctype": "Account", "account_name": "VAT - Test",
-		"parent_account": "Tax Assets - %s" % abbr, "company": company,
+		"parent_account": "_Test Tax Assets - %s" % abbr, "company": company,
 		"group_or_ledger": "Ledger"})
 		
 	# create BOM
diff --git a/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt b/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
index e1ceb05..2e5b219 100755
--- a/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
+++ b/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-28 10:06:02", 
+  "creation": "2013-01-30 12:49:56", 
   "docstatus": 0, 
-  "modified": "2013-01-29 16:28:06", 
+  "modified": "2013-02-07 10:50:00", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py
index 7c3cbd6..a4ee370 100644
--- a/stock/doctype/warehouse/warehouse.py
+++ b/stock/doctype/warehouse/warehouse.py
@@ -18,7 +18,6 @@
 import webnotes
 
 from webnotes.utils import cstr, flt, validate_email_add
-from webnotes.model.doc import Document
 from webnotes.model.code import get_obj
 from webnotes import msgprint
 
@@ -204,7 +203,15 @@
 		# delete cancelled sle
 		if sql("""select name from `tabStock Ledger Entry` 
 				where warehouse = %s and ifnull('is_cancelled', '') = 'No'""", self.doc.name):
-			mdgprint("""Warehosue can not be deleted as stock ledger entry 
-				exists for this warehosue.""", raise_exception=1)
+			msgprint("""Warehosue can not be deleted as stock ledger entry 
+				exists for this warehouse.""", raise_exception=1)
 		else:
-			sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
\ No newline at end of file
+			sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
+			
+test_records = [
+	[{
+		"doctype": "Warehouse",
+		"warehouse_name": "_Test Warehouse",
+		"warehouse_type": "_Test Warehouse Type"
+	}]
+]
\ No newline at end of file
diff --git a/stock/utils.py b/stock/utils.py
index 87f4c02..3b98cf0 100644
--- a/stock/utils.py
+++ b/stock/utils.py
@@ -148,7 +148,7 @@
 		
 	return valid_serial_nos
 	
-def get_warehouse_list(doctype, txt, searchfield, start, page_len):
+def get_warehouse_list(doctype, txt, searchfield, start, page_len, args):
 	"""used in search queries"""
 	wlist = []
 	for w in webnotes.conn.sql_list("""select name from tabWarehouse