From 51a140a2bd34f0b0eb656e5867c8e132a9492ee0 Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Fri, 29 May 2026 16:56:29 +0530 Subject: [PATCH 1/4] fix(stock): allow to create quality inspection after purchase/delivery (cherry picked from commit c6a88ab1d21d11663a991322dbbff6a7b7d61d85) # Conflicts: # erpnext/controllers/stock_controller.py --- erpnext/controllers/stock_controller.py | 33 ++++++++++++++++---- erpnext/public/js/controllers/transaction.js | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 7e3f00774fe..e24503f4408 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -2112,7 +2112,11 @@ def repost_required_for_queue(doc: StockController) -> bool: @frappe.whitelist() +<<<<<<< HEAD def check_item_quality_inspection(doctype, items): +======= +def check_item_quality_inspection(doctype: str, docstatus: str | int, items: str | list[dict]): +>>>>>>> c6a88ab1d2 (fix(stock): allow to create quality inspection after purchase/delivery) if isinstance(items, str): items = json.loads(items) @@ -2124,13 +2128,30 @@ def check_item_quality_inspection(doctype, items): "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 d0eeb58495b..ead1639f5cb 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2929,6 +2929,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 1679680d8e2b62a65e5475cae99ee5329b1ce4d5 Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Fri, 29 May 2026 18:06:32 +0530 Subject: [PATCH 2/4] fix(stock): add warning message to notify the user to configure the inspection (cherry picked from commit e003fe4de0b9fa59a054bfa348837d8ba1acf9ab) --- 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 ead1639f5cb..f8abb214533 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2934,6 +2934,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; From 8d12a895583e159373b9c90c1e392274cdb94d2b Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 1 Jun 2026 22:07:42 +0530 Subject: [PATCH 3/4] chore: fixed conflicts --- erpnext/controllers/stock_controller.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index e24503f4408..484377a5dcc 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -2112,11 +2112,7 @@ def repost_required_for_queue(doc: StockController) -> bool: @frappe.whitelist() -<<<<<<< HEAD -def check_item_quality_inspection(doctype, items): -======= -def check_item_quality_inspection(doctype: str, docstatus: str | int, items: str | list[dict]): ->>>>>>> c6a88ab1d2 (fix(stock): allow to create quality inspection after purchase/delivery) +def check_item_quality_inspection(doctype: str, items: str | list[dict]): if isinstance(items, str): items = json.loads(items) From 980cefa16991fee85dc9dd20261c07703cddc6e1 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 1 Jun 2026 22:10:06 +0530 Subject: [PATCH 4/4] chore: fixed conflicts --- erpnext/controllers/stock_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 484377a5dcc..9762623d97e 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -2112,7 +2112,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)