From d61ad3bd95a14dc432512722bf2b77d415a561f9 Mon Sep 17 00:00:00 2001 From: kavin-114 Date: Sat, 28 Feb 2026 13:01:07 +0530 Subject: [PATCH 1/4] fix(stock): pass company to avoid document naming rule issue in QI When a Document Naming Rule is configured in QI with a condition based on the company, the system was not passing the company value properly. As a result, the naming rule condition was skipped and the document name was generated using the default series. This fix ensures that the company is passed correctly so that the configured Document Naming Rule is evaluated and applied as expected. (cherry picked from commit 74def423ed5b3d7f2960100a306341b2547cf90e) # Conflicts: # erpnext/controllers/stock_controller.py --- erpnext/controllers/stock_controller.py | 7 +++++++ erpnext/public/js/controllers/transaction.js | 1 + 2 files changed, 8 insertions(+) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 0ae1d232171..13df4f5d34b 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -2128,7 +2128,13 @@ def check_item_quality_inspection(doctype, items): @frappe.whitelist() +<<<<<<< HEAD def make_quality_inspections(doctype, docname, items, inspection_type): +======= +def make_quality_inspections( + company: str, doctype: str, docname: str, items: str | list, inspection_type: str +): +>>>>>>> 74def423ed (fix(stock): pass company to avoid document naming rule issue in QI) if isinstance(items, str): items = json.loads(items) @@ -2147,6 +2153,7 @@ def make_quality_inspections(doctype, docname, items, inspection_type): quality_inspection = frappe.get_doc( { + "company": company, "doctype": "Quality Inspection", "inspection_type": inspection_type, "inspected_by": frappe.session.user, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index aa02eec7b62..650611ee709 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2966,6 +2966,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe frappe.call({ method: "erpnext.controllers.stock_controller.make_quality_inspections", args: { + company: me.frm.doc.company, doctype: me.frm.doc.doctype, docname: me.frm.doc.name, items: selected_data, From 384498282463eb61f77d26510c66c4cfff14090c Mon Sep 17 00:00:00 2001 From: kavin-114 Date: Sat, 28 Feb 2026 16:36:22 +0530 Subject: [PATCH 2/4] test: add unit test to handle company condition in naming rule (cherry picked from commit 4c39cf2d650207c3d02d1da8490fcf2657ddc488) --- .../doctype/stock_entry/test_stock_entry.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 04f87d3348e..583cb4bedc6 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -2415,6 +2415,54 @@ class TestStockEntry(IntegrationTestCase): frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 5)).submit() frappe.get_doc(_make_stock_entry(work_order.name, "Manufacture", 5)).submit() + def test_qi_creation_with_naming_rule_company_condition(self): + """ + Unit test case to check the document naming rule with company condition + For Quality Inspection, when created from Stock Entry. + """ + from erpnext.accounts.report.trial_balance.test_trial_balance import create_company + from erpnext.controllers.stock_controller import make_quality_inspections + from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse + + # create a separate company to handle document naming rule with company condition + qc_company = create_company(company_name="Test Quality Company") + + # create document naming rule based on that for Quality Inspection Doctype + qc_naming_rule = frappe.new_doc( + "Document Naming Rule", document_type="Quality Inspection", prefix="NQC.-ST-", prefix_digits=5 + ) + qc_naming_rule.append("conditions", {"field": "company", "condition": "=", "value": qc_company}) + qc_naming_rule.save() + + warehouse = create_warehouse(warehouse_name="Test QI Warehouse", company=qc_company) + item = create_item( + item_code="Test QI DNR Item", + is_stock_item=1, + ) + + # create inward stock entry + stock_entry = make_stock_entry( + item_code=item.item_code, + target=warehouse, + qty=10, + basic_rate=100, + inspection_required=True, + do_not_submit=True, + ) + + # create QI from Stock Entry and check the naming series generated. + qi = make_quality_inspections( + stock_entry.company, + stock_entry.doctype, + stock_entry.name, + stock_entry.as_dict().get("items"), + "Incoming", + ) + self.assertEqual(qi[0], "NQC-ST-00001") + + # delete naming rule + frappe.delete_doc("Document Naming Rule", qc_naming_rule.name) + def make_serialized_item(self, **args): args = frappe._dict(args) From 417e8a43718f7156891abbbadfedec066ce64445 Mon Sep 17 00:00:00 2001 From: kavin-114 Date: Mon, 2 Mar 2026 13:05:27 +0530 Subject: [PATCH 3/4] fix: pass company in test case using make_quality_inspections (cherry picked from commit 397de1274f17dfea53f2c9e4fc7aaea8a33cb8cc) --- .../doctype/quality_inspection/test_quality_inspection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index 8c4622a8ae2..3885df7c74a 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -142,7 +142,9 @@ class TestQualityInspection(IntegrationTestCase): inspection_type = "Outgoing" for item in dn.items: item.sample_size = item.qty - quality_inspections = make_quality_inspections(dn.doctype, dn.name, dn.items, inspection_type) + quality_inspections = make_quality_inspections( + dn.company, dn.doctype, dn.name, dn.items, inspection_type + ) self.assertEqual(len(dn.items), len(quality_inspections)) # cleanup From 3e8ebf8c14589a8a75958bc336fc8aad474995be Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 3 Mar 2026 20:44:40 +0530 Subject: [PATCH 4/4] chore: resolve 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 13df4f5d34b..5436cd3e54f 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -2128,13 +2128,9 @@ def check_item_quality_inspection(doctype, items): @frappe.whitelist() -<<<<<<< HEAD -def make_quality_inspections(doctype, docname, items, inspection_type): -======= def make_quality_inspections( company: str, doctype: str, docname: str, items: str | list, inspection_type: str ): ->>>>>>> 74def423ed (fix(stock): pass company to avoid document naming rule issue in QI) if isinstance(items, str): items = json.loads(items)