Merge branch 'develop'
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 1850146..6dd2447 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 import frappe
 
-__version__ = '7.0.5'
+__version__ = '7.0.6'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 3e31d5e..6971e0d 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -279,7 +279,7 @@
 erpnext.patches.v7_0.update_mins_to_first_response
 erpnext.patches.v6_20x.repost_valuation_rate_for_negative_inventory
 erpnext.patches.v7_0.system_settings_setup_complete
-erpnext.patches.v7_0.set_naming_series_for_timesheet
+erpnext.patches.v7_0.set_naming_series_for_timesheet #2016-07-27
 execute:frappe.reload_doc('projects', 'doctype', 'project')
 execute:frappe.reload_doc('projects', 'doctype', 'project_user')
 erpnext.patches.v7_0.convert_timelogbatch_to_timesheet
@@ -303,3 +303,4 @@
 erpnext.patches.v7_0.remove_administrator_role_in_doctypes
 erpnext.patches.v7_0.rename_fee_amount_to_fee_component
 erpnext.patches.v7_0.calculate_total_costing_amount
+erpnext.patches.v7_0.fix_nonwarehouse_ledger_gl_entries_for_transactions
diff --git a/erpnext/patches/v7_0/calculate_total_costing_amount.py b/erpnext/patches/v7_0/calculate_total_costing_amount.py
index 3163517..4da839f 100644
--- a/erpnext/patches/v7_0/calculate_total_costing_amount.py
+++ b/erpnext/patches/v7_0/calculate_total_costing_amount.py
@@ -11,5 +11,6 @@
 			ts.update_cost()
 			ts.calculate_total_amounts()
 			ts.flags.ignore_validate = True
+			ts.flags.ignore_mandatory = True
 			ts.flags.ignore_validate_update_after_submit = True
 			ts.save()
diff --git a/erpnext/patches/v7_0/fix_nonwarehouse_ledger_gl_entries_for_transactions.py b/erpnext/patches/v7_0/fix_nonwarehouse_ledger_gl_entries_for_transactions.py
new file mode 100644
index 0000000..ff9d48a
--- /dev/null
+++ b/erpnext/patches/v7_0/fix_nonwarehouse_ledger_gl_entries_for_transactions.py
@@ -0,0 +1,50 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	if not frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock"):
+		return
+	
+	frappe.reload_doctype("Account")
+
+	warehouses = frappe.db.sql_list("""select name from tabAccount
+		where account_type = 'Stock' and is_group = 0
+		and (warehouse is null or warehouse = '')""")
+	if warehouses:
+		warehouses = set_warehouse_for_stock_account(warehouses)
+
+		stock_vouchers = frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
+			from `tabStock Ledger Entry` sle
+			where sle.warehouse in (%s) and creation > '2016-05-01'
+			and not exists(select name from `tabGL Entry` 
+				where account=sle.warehosue and voucher_type=sle.voucher_type and voucher_no=sle.voucher_no)
+			order by sle.posting_date""" %
+			', '.join(['%s']*len(warehouses)), tuple(warehouses))
+
+		rejected = []
+		for voucher_type, voucher_no in stock_vouchers:
+			try:
+				frappe.db.sql("""delete from `tabGL Entry`
+					where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
+
+				voucher = frappe.get_doc(voucher_type, voucher_no)
+				voucher.make_gl_entries()
+				frappe.db.commit()
+			except Exception, e:
+				print frappe.get_traceback()
+				rejected.append([voucher_type, voucher_no])
+				frappe.db.rollback()
+
+		print rejected
+
+def set_warehouse_for_stock_account(warehouse_account):
+	for account in warehouse_account:
+		if frappe.db.exists('Warehouse', account):
+			frappe.db.set_value("Account", account, "warehouse", account)
+		else:
+			warehouse_account.remove(account)
+
+	return warehouse_account
\ No newline at end of file
diff --git a/erpnext/schools/doctype/fee_structure/fee_structure.py b/erpnext/schools/doctype/fee_structure/fee_structure.py
index b4fc279..b71c507 100644
--- a/erpnext/schools/doctype/fee_structure/fee_structure.py
+++ b/erpnext/schools/doctype/fee_structure/fee_structure.py
@@ -13,6 +13,6 @@
 	def calculate_total(self):
 		"""Calculates total amount."""
 		self.total_amount = 0
-		for d in self.amount:
+		for d in self.components:
 			self.total_amount += d.amount
 	
diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py
index 2777d3d..d5d6f9d 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.py
+++ b/erpnext/stock/report/stock_balance/stock_balance.py
@@ -71,9 +71,11 @@
 		conditions += " and item_code = '%s'" % frappe.db.escape(filters.get("item_code"), percent=False)
 
 	if filters.get("warehouse"):
-		lft, rgt = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"])
-		conditions += " and exists (select name from `tabWarehouse` wh \
-			where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(lft, rgt)
+		warehouse_details = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1)
+		if warehouse_details:
+			conditions += " and exists (select name from `tabWarehouse` wh \
+				where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(warehouse_details.lft,
+				warehouse_details.rgt)
 
 	return conditions
 
diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py
index b2e4670..69fb490 100644
--- a/erpnext/stock/report/stock_ledger/stock_ledger.py
+++ b/erpnext/stock/report/stock_ledger/stock_ledger.py
@@ -99,8 +99,10 @@
 	return row
 	
 def get_warehouse_condition(warehouse):
-	lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
-	
-	return " exists (select name from `tabWarehouse` wh \
-		where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(lft, rgt)
-	
\ No newline at end of file
+	warehouse_details = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"], as_dict=1)
+	if warehouse_details:
+		return " exists (select name from `tabWarehouse` wh \
+			where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(warehouse_details.lft,
+			warehouse_details.rgt)
+
+	return ''
diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
index f90fb49..21287b9 100644
--- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
+++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
@@ -63,10 +63,12 @@
 		conditions.append("item_code = '%s' "%filters.item_code)
 		
 	if filters.warehouse:
-		lft, rgt = frappe.db.get_value("Warehouse", filters.warehouse, ["lft", "rgt"])
-	
-		conditions.append(" exists (select name from `tabWarehouse` wh \
-			where wh.lft >= %s and wh.rgt <= %s and bin.warehouse = wh.name)"%(lft, rgt))
+		warehouse_details = frappe.db.get_value("Warehouse", filters.warehouse, ["lft", "rgt"], as_dict=1)
+
+		if warehouse_details:
+			conditions.append(" exists (select name from `tabWarehouse` wh \
+				where wh.lft >= %s and wh.rgt <= %s and bin.warehouse = wh.name)"%(warehouse_details.lft,
+				warehouse_details.rgt))
 
 	bin_list = frappe.db.sql("""select item_code, warehouse, actual_qty, planned_qty, indented_qty,
 		ordered_qty, reserved_qty, reserved_qty_for_production, projected_qty