Warehouse Account Linking (#9292)

* [enhance] Added account in the warehouse

* documentation

* patch to move account head from account to warehouse

* fixed test cases

* Fixes in warehouse-account linking

* minor fix in test case
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 3649cc1..822712f 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -10,6 +10,7 @@
 from erpnext.accounts.general_ledger import make_gl_entries, delete_gl_entries, process_gl_map
 from erpnext.controllers.accounts_controller import AccountsController
 from erpnext.stock.stock_ledger import get_valuation_rate
+from erpnext.stock import get_warehouse_account_map
 
 class StockController(AccountsController):
 	def validate(self):
@@ -21,7 +22,7 @@
 			delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
 
 		if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
-			warehouse_account = get_warehouse_account()
+			warehouse_account = get_warehouse_account_map()
 
 			if self.docstatus==1:
 				if not gl_entries:
@@ -37,7 +38,7 @@
 			default_cost_center=None):
 
 		if not warehouse_account:
-			warehouse_account = get_warehouse_account()
+			warehouse_account = get_warehouse_account_map()
 
 		sle_map = self.get_stock_ledger_details()
 		voucher_details = self.get_voucher_details(default_expense_account, default_cost_center, sle_map)
@@ -66,7 +67,7 @@
 							sle = self.update_stock_ledger_entries(sle)
 
 						gl_list.append(self.get_gl_dict({
-							"account": warehouse_account[sle.warehouse]["name"],
+							"account": warehouse_account[sle.warehouse]["account"],
 							"against": item_row.expense_account,
 							"cost_center": item_row.cost_center,
 							"remarks": self.get("remarks") or "Accounting Entry for Stock",
@@ -76,7 +77,7 @@
 						# to target warehouse / expense account
 						gl_list.append(self.get_gl_dict({
 							"account": item_row.expense_account,
-							"against": warehouse_account[sle.warehouse]["name"],
+							"against": warehouse_account[sle.warehouse]["account"],
 							"cost_center": item_row.cost_center,
 							"remarks": self.get("remarks") or "Accounting Entry for Stock",
 							"credit": flt(sle.stock_value_difference, 2),
@@ -88,10 +89,7 @@
 		if warehouse_with_no_account:
 			for wh in warehouse_with_no_account:
 				if frappe.db.get_value("Warehouse", wh, "company"):
-					frappe.throw(_("Warehouse {0} is not linked to any account, please create/link the corresponding (Asset) account for the warehouse.").format(wh))
-
-			msgprint(_("No accounting entries for the following warehouses") + ": \n" +
-				"\n".join(warehouse_with_no_account))
+					frappe.throw(_("Warehouse {0} is not linked to any account, please mention the account in  the warehouse record or set default inventory account in company {1}.").format(wh, self.company))
 
 		return process_gl_map(gl_list)
 
@@ -341,7 +339,7 @@
 			where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
 
 	if not warehouse_account:
-		warehouse_account = get_warehouse_account()
+		warehouse_account = get_warehouse_account_map()
 
 	future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items)
 	gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date)
@@ -405,22 +403,4 @@
 			tuple([posting_date] + [d[1] for d in future_stock_vouchers]), as_dict=1):
 				gl_entries.setdefault((d.voucher_type, d.voucher_no), []).append(d)
 
-	return gl_entries
-
-def get_warehouse_account():
-	if not frappe.flags.warehouse_account_map or frappe.flags.in_test:
-		warehouse_account = frappe._dict()
-
-		for d in frappe.db.sql("""select
-				warehouse, name, account_currency
-			from
-				tabAccount
-			where
-				account_type = 'Stock'
-				and (warehouse is not null and warehouse != '')
-				and is_group=0 """, as_dict=1):
-			warehouse_account.setdefault(d.warehouse, d)
-
-		frappe.flags.warehouse_account_map = warehouse_account
-
-	return frappe.flags.warehouse_account_map
+	return gl_entries
\ No newline at end of file