Merge branch 'develop' into fix-asset-warehouse-validation
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 57bc0a7..e6a46d0 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -249,8 +249,9 @@
def validate_warehouse(self, for_validate=True):
if self.update_stock and for_validate:
+ stock_items = self.get_stock_items()
for d in self.get("items"):
- if not d.warehouse:
+ if not d.warehouse and d.item_code in stock_items:
frappe.throw(
_(
"Row No {0}: Warehouse is required. Please set a Default Warehouse for Item {1} and Company {2}"
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 72ac1b3..3ad61d4 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -1264,6 +1264,9 @@
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:
@@ -1279,6 +1282,7 @@
)
]
+ self._stock_items = stock_items
return stock_items
def set_total_advance_paid(self):