From 10664b7b9539f822e126014c9e8dae418ce818d6 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/public/js/controllers/transaction.js --- erpnext/controllers/stock_controller.py | 33 ++++++++++++++++---- erpnext/public/js/controllers/transaction.js | 5 +++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index a4ee4daadb9..bc393452483 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -1680,7 +1680,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) @@ -1692,13 +1696,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 7c1981973a9..649ed24b789 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2506,7 +2506,12 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe method: "erpnext.controllers.stock_controller.check_item_quality_inspection", args: { doctype: this.frm.doc.doctype, +<<<<<<< HEAD items: this.frm.doc.items +======= + docstatus: this.frm.doc.docstatus, + items: this.frm.doc.items, +>>>>>>> c6a88ab1d2 (fix(stock): allow to create quality inspection after purchase/delivery) }, freeze: true, callback: function (r) { From 42e2fd5fc98c4881aadfa9959a0fb725e287109c 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) # Conflicts: # erpnext/public/js/controllers/transaction.js --- erpnext/public/js/controllers/transaction.js | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 649ed24b789..b6d484f6561 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2515,7 +2515,28 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe }, freeze: true, callback: function (r) { +<<<<<<< HEAD r.message.forEach(item => { +======= + 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) => { +>>>>>>> e003fe4de0 (fix(stock): add warning message to notify the user to configure the inspection) if (me.has_inspection_required(item)) { let dialog_items = dialog.fields_dict.items; dialog_items.df.data.push({ From 54cbc9116613fa5f969d9acde607929a42cf94ea Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 1 Jun 2026 22:11:58 +0530 Subject: [PATCH 3/4] chore: fixed conflicts --- erpnext/controllers/stock_controller.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index bc393452483..d9ca43bab60 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -1680,11 +1680,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) if isinstance(items, str): items = json.loads(items) From 897722c35f48dbff1be5056a159765b7dea12b47 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Mon, 1 Jun 2026 22:14:46 +0530 Subject: [PATCH 4/4] chore: fixed conflicts --- erpnext/public/js/controllers/transaction.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index b6d484f6561..42163c1a6c3 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2506,18 +2506,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe method: "erpnext.controllers.stock_controller.check_item_quality_inspection", args: { doctype: this.frm.doc.doctype, -<<<<<<< HEAD - items: this.frm.doc.items -======= docstatus: this.frm.doc.docstatus, items: this.frm.doc.items, ->>>>>>> c6a88ab1d2 (fix(stock): allow to create quality inspection after purchase/delivery) }, freeze: true, callback: function (r) { -<<<<<<< HEAD - r.message.forEach(item => { -======= if (r.message.length == 0) { let type = inspection_type === "Incoming" ? "Purchase" : "Delivery"; let fieldname = @@ -2536,7 +2529,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } r.message.forEach((item) => { ->>>>>>> e003fe4de0 (fix(stock): add warning message to notify the user to configure the inspection) if (me.has_inspection_required(item)) { let dialog_items = dialog.fields_dict.items; dialog_items.df.data.push({