From c6a88ab1d21d11663a991322dbbff6a7b7d61d85 Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Fri, 29 May 2026 16:56:29 +0530 Subject: [PATCH 1/2] fix(stock): allow to create quality inspection after purchase/delivery --- erpnext/controllers/stock_controller.py | 31 +++++++++++++++----- erpnext/public/js/controllers/transaction.js | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 9fb9dfe58ab..5d5f83793bc 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -2113,7 +2113,7 @@ def repost_required_for_queue(doc: StockController) -> bool: @frappe.whitelist() -def check_item_quality_inspection(doctype: str, items: str | list[dict]): +def check_item_quality_inspection(doctype: str, docstatus: str | int, items: str | list[dict]): if isinstance(items, str): items = json.loads(items) @@ -2125,13 +2125,30 @@ def check_item_quality_inspection(doctype: str, items: str | list[dict]): "Delivery Note": "inspection_required_before_delivery", } - items_to_remove = [] - for item in items: - if not frappe.db.get_value("Item", item.get("item_code"), inspection_fieldname_map.get(doctype)): - items_to_remove.append(item) - items = [item for item in items if item not in items_to_remove] + inspection_fieldname = inspection_fieldname_map.get(doctype) + if inspection_fieldname is None: + return [] - return items + allow_after_transaction = cint(docstatus) == 1 and frappe.get_single_value( + "Stock Settings", "allow_to_make_quality_inspection_after_purchase_or_delivery" + ) + + if allow_after_transaction: + return items + + item_codes = list({item.get("item_code") for item in items}) + + Item = frappe.qb.DocType("Item") + results = ( + frappe.qb.from_(Item) + .select(Item.name) + .where((Item.name.isin(item_codes)) & (Item[inspection_fieldname] == 1)) + .run(as_dict=True) + ) + + inspection_required_items = {row.name for row in results} + + return [item for item in items if item.get("item_code") in inspection_required_items] @frappe.whitelist() diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 15271ed66a6..58679efbbb0 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2923,6 +2923,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe method: "erpnext.controllers.stock_controller.check_item_quality_inspection", args: { doctype: this.frm.doc.doctype, + docstatus: this.frm.doc.docstatus, items: this.frm.doc.items, }, freeze: true, From e003fe4de0b9fa59a054bfa348837d8ba1acf9ab Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Fri, 29 May 2026 18:06:32 +0530 Subject: [PATCH 2/2] fix(stock): add warning message to notify the user to configure the inspection --- erpnext/public/js/controllers/transaction.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 58679efbbb0..d8ab45648ed 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2928,6 +2928,23 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe }, freeze: true, callback: function (r) { + if (r.message.length == 0) { + let type = inspection_type === "Incoming" ? "Purchase" : "Delivery"; + let fieldname = + inspection_type === "Incoming" + ? "Inspection Required before Purchase" + : "Inspection Required before Delivery"; + + frappe.msgprint({ + title: __("Quality Inspection Not Configured"), + message: __(`Enable {0} on the Item master to proceed with {1} inspection.`, [ + fieldname, + type, + ]), + }); + return; + } + r.message.forEach((item) => { if (me.has_inspection_required(item)) { let dialog_items = dialog.fields_dict.items;