From 00778c9a1e960b02149cbda707bcb17af74fe1f4 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 25 Jun 2014 19:12:24 +0530 Subject: [PATCH] Validate expense account for perpetual inventory --- erpnext/controllers/stock_controller.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 83cec985ca..bb3ab69ca1 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -238,7 +238,11 @@ class StockController(AccountsController): frappe.throw(_("Expense or Difference account is mandatory for Item {0} as it impacts overall stock value").format(item.item_code)) else: - is_expense_account = frappe.db.get_value("Account", item.get("expense_account"), "report_type")=="Profit and Loss" + is_expense_account = frappe.db.get_value("Account", + item.get("expense_account"), "report_type")=="Profit and Loss" + if self.doctype != "Purchase Receipt" and not is_expense_account: + frappe.throw(_("Expense / Difference account ({0}) must be a 'Profit or Loss' account") + .format(item.get("expense_account"))) if is_expense_account and not item.get("cost_center"): frappe.throw(_("{0} {1}: Cost Center is mandatory for Item {2}").format( _(self.doctype), self.name, item.get("item_code")))