diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index b7ff5fbfbd82f3c144ee8361472a49a232d8c851..1c98618cae5828204c0396bd35f817c1e8ffe300 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -65,6 +65,18 @@ class StockController(AccountsController): self.validate_internal_transfer() self.validate_putaway_capacity() + def validate_items_exist(self): + if not self.get("items"): + return + + items = [d.item_code for d in self.get("items")] + + exists_items = frappe.get_all("Item", filters={"name": ("in", items)}, pluck="name") + non_exists_items = set(items) - set(exists_items) + + if non_exists_items: + frappe.throw(_("Items {0} do not exist in the Item master.").format(", ".join(non_exists_items))) + def validate_duplicate_serial_and_batch_bundle(self, table_name): if not self.get(table_name): return diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index fb2563a553608b82841f805f15142053e29d4165..3d6abecee3e3d959f4525e01c0e5252dbe6a44c9 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -34,6 +34,7 @@ class StockReconciliation(StockController): self.head_row = ["Item Code", "Warehouse", "Quantity", "Valuation Rate"] def validate(self): + self.validate_items_exist() if not self.expense_account: self.expense_account = frappe.get_cached_value( "Company", self.company, "stock_adjustment_account" @@ -133,6 +134,9 @@ class StockReconciliation(StockController): def set_current_serial_and_batch_bundle(self, voucher_detail_no=None, save=False) -> None: """Set Serial and Batch Bundle for each item""" for item in self.items: + if not frappe.db.exists("Item", item.item_code): + frappe.throw(_("Item {0} does not exist").format(item.item_code)) + if not item.reconcile_all_serial_batch and item.serial_and_batch_bundle: bundle = self.get_bundle_for_specific_serial_batch(item) item.current_serial_and_batch_bundle = bundle.name @@ -328,6 +332,9 @@ class StockReconciliation(StockController): def set_new_serial_and_batch_bundle(self): for item in self.items: + if not item.item_code: + continue + if item.use_serial_batch_fields: continue