diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 8e55514194e..f5983c326f3 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -209,7 +209,8 @@ class PurchaseInvoice(BuyingController): if self.update_stock: self.validate_item_code() self.validate_warehouse() - warehouse_account = get_warehouse_account_map() + if auto_accounting_for_stock: + warehouse_account = get_warehouse_account_map() for item in self.get("items"): # in case of auto inventory accounting, @@ -402,7 +403,8 @@ class PurchaseInvoice(BuyingController): # item gl entries stock_items = self.get_stock_items() expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") - warehouse_account = get_warehouse_account_map() + if self.update_stock and self.auto_accounting_for_stock: + warehouse_account = get_warehouse_account_map() voucher_wise_stock_value = {} if self.update_stock: diff --git a/erpnext/stock/__init__.py b/erpnext/stock/__init__.py index 06f424e5b2f..ea3d1036d2d 100644 --- a/erpnext/stock/__init__.py +++ b/erpnext/stock/__init__.py @@ -53,9 +53,9 @@ def get_warehouse_account(warehouse, warehouse_account=None): if not account and warehouse.company: account = get_company_default_inventory_account(warehouse.company) - if not account: + if not account and warehouse.company: frappe.throw(_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}") - .format(warehouse, warehouse.company)) + .format(warehouse.name, warehouse.company)) return account def get_company_default_inventory_account(company): diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 850d648e72d..ef63740650f 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -22,10 +22,11 @@ class Warehouse(NestedSet): def onload(self): '''load account name for General Ledger Report''' - account = self.account or get_warehouse_account(self) + if self.company and cint(frappe.db.get_value("Company", self.company, "enable_perpetual_inventory")): + account = self.account or get_warehouse_account(self) - if account: - self.set_onload('account', account) + if account: + self.set_onload('account', account) load_address_and_contact(self)