From ad91d57a419a1c0d7fd8b85e12aaf32e6725439a Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Tue, 29 Mar 2022 18:43:33 +0530 Subject: [PATCH] perf: skip warehouse validation for non-stock items (cherry picked from commit 6528218ac31001e04e6b5ebfa0f3d429e296742f) # Conflicts: # erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py --- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 6 ++++++ erpnext/controllers/accounts_controller.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index a026445831d..716bda0d33e 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -245,9 +245,15 @@ class PurchaseInvoice(BuyingController): def validate_warehouse(self, for_validate=True): if self.update_stock and for_validate: +<<<<<<< HEAD <<<<<<< HEAD for d in self.get("items"): if not d.warehouse: +======= + stock_items = self.get_stock_items() + for d in self.get("items"): + if not d.warehouse and d.item_code in stock_items: +>>>>>>> 6528218ac3 (perf: skip warehouse validation for non-stock items) frappe.throw( _( "Warehouse required at Row No {0}, please set default warehouse for the item {1} for the company {2}" diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index f0143962874..964d8fb06fe 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1265,6 +1265,9 @@ class AccountsController(TransactionBase): return get_company_default(self.company, fieldname, ignore_validation=ignore_validation) def get_stock_items(self): + if hasattr(self, "_stock_items") and self._stock_items: + return self._stock_items + stock_items = [] item_codes = list(set(item.item_code for item in self.get("items"))) if item_codes: @@ -1280,6 +1283,7 @@ class AccountsController(TransactionBase): ) ] + self._stock_items = stock_items return stock_items def set_total_advance_paid(self):