From cccc45edc57159f60d9d4c3a31db3ef6383d1296 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 5 Oct 2016 17:15:43 +0530 Subject: [PATCH] Don't throw expense account validation on fetching item details --- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 6 +++--- erpnext/controllers/accounts_controller.py | 4 ++-- erpnext/controllers/buying_controller.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 914c9be0a8..d741a6008a 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -58,7 +58,7 @@ class PurchaseInvoice(BuyingController): self.check_for_closed_status() self.validate_with_previous_doc() self.validate_uom_is_integer("uom", "qty") - self.set_expense_account() + self.set_expense_account(for_validate=True) self.set_against_expense_account() self.validate_write_off_account() self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount", "items") @@ -155,7 +155,7 @@ class PurchaseInvoice(BuyingController): super(PurchaseInvoice, self).validate_warehouse() - def set_expense_account(self): + def set_expense_account(self, for_validate=False): auto_accounting_for_stock = cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) if auto_accounting_for_stock: @@ -181,7 +181,7 @@ class PurchaseInvoice(BuyingController): else: item.expense_account = stock_not_billed_account - elif not item.expense_account: + elif not item.expense_account and for_validate: throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name)) def set_against_expense_account(self): diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 8927da7f78..e245875468 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -144,7 +144,7 @@ class AccountsController(TransactionBase): self.conversion_rate = get_exchange_rate(self.currency, self.company_currency) - def set_missing_item_details(self): + def set_missing_item_details(self, for_validate=False): """set missing item values""" from erpnext.stock.get_item_details import get_item_details @@ -196,7 +196,7 @@ class AccountsController(TransactionBase): (1.0 - (flt(item.discount_percentage) / 100.0)), item.precision("rate")) if self.doctype == "Purchase Invoice": - self.set_expense_account() + self.set_expense_account(for_validate) def set_taxes(self): if not self.meta.get_field("taxes"): diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 88acfb7c17..8bc081b3b5 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -62,7 +62,7 @@ class BuyingController(StockController): if getattr(self, "supplier", None): self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions)) - self.set_missing_item_details() + self.set_missing_item_details(for_validate) def set_supplier_from_item_default(self): if self.meta.get_field("supplier") and not self.supplier: