Validate accounting entry agaist Stock account if perpetual inventory enabled
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 8fc785c..7276d41 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -82,14 +82,15 @@
 	gle.submit()
 
 def validate_account_for_auto_accounting_for_stock(gl_map):
-	if gl_map[0].voucher_type=="Journal Entry":
-		aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
-			where account_type = 'Warehouse' and ifnull(warehouse, '')!=''""")]
+	if cint(frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock")) \
+		and gl_map[0].voucher_type=="Journal Entry":
+			aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount
+				where account_type = 'Warehouse' and ifnull(warehouse, '')!=''""")]
 
-		for entry in gl_map:
-			if entry.account in aii_accounts:
-				frappe.throw(_("Account: {0} can only be updated via Stock Transactions")
-					.format(entry.account), StockAccountInvalidTransaction)
+			for entry in gl_map:
+				if entry.account in aii_accounts:
+					frappe.throw(_("Account: {0} can only be updated via Stock Transactions")
+						.format(entry.account), StockAccountInvalidTransaction)
 
 def round_off_debit_credit(gl_map):
 	precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"),