From c65f1607762f1f2b5f6905ea867c4483657f4db2 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sun, 26 Jun 2016 08:25:03 +0530 Subject: [PATCH] [fix] Identify account group for warehouse based on account type --- erpnext/stock/doctype/warehouse/warehouse.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index f1f1e705a0..57da471000 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -74,12 +74,13 @@ class Warehouse(NestedSet): frappe.throw(_("Warehouse {0}: Company is mandatory").format(self.name)) if not self.create_account_under: - parent_account = frappe.db.get_value("Account", - {"account_name": "Stock Assets", "company": self.company}) + parent_account = frappe.db.sql("""select name from tabAccount + where account_type='Stock' and company=%s and is_group=1 + and (warehouse is null or warehouse = '')""", self.company) if parent_account: - frappe.db.set_value("Warehouse", self.name, "create_account_under", parent_account) - self.create_account_under = parent_account + frappe.db.set_value("Warehouse", self.name, "create_account_under", parent_account[0][0]) + self.create_account_under = parent_account[0][0] else: frappe.throw(_("Please enter parent account group for warehouse {0}").format(self.name)) elif frappe.db.get_value("Account", self.create_account_under, "company") != self.company: