From 10b40836a99cc3e387a9c8ddd56f90b231de1484 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 15:56:44 +0000 Subject: [PATCH] Merge pull request #53128 from frappe/mergify/bp/version-15-hotfix/pr-53037 fix(stock): pass company to avoid document naming rule issue in QI (backport #53037) --- erpnext/controllers/stock_controller.py | 3 +- erpnext/public/js/controllers/transaction.js | 1 + .../test_quality_inspection.py | 3 +- .../doctype/stock_entry/test_stock_entry.py | 47 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index a07f1e3e757..5d1af9ea394 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -1702,7 +1702,7 @@ def check_item_quality_inspection(doctype, items): @frappe.whitelist() -def make_quality_inspections(doctype, docname, items): +def make_quality_inspections(company, doctype, docname, items): if isinstance(items, str): items = json.loads(items) @@ -1721,6 +1721,7 @@ def make_quality_inspections(doctype, docname, items): quality_inspection = frappe.get_doc( { + "company": company, "doctype": "Quality Inspection", "inspection_type": "Incoming", "inspected_by": frappe.session.user, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 2e782b49e66..ef727eec8d8 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2476,6 +2476,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, diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index b0b67d8c8ea..e49a0b3b678 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -140,7 +140,8 @@ class TestQualityInspection(FrappeTestCase): dn = create_delivery_note(item_code="_Test Item with QA", do_not_submit=True) for item in dn.items: item.sample_size = item.qty - quality_inspections = make_quality_inspections(dn.doctype, dn.name, dn.items) + + quality_inspections = make_quality_inspections(dn.company, dn.doctype, dn.name, dn.items) self.assertEqual(len(dn.items), len(quality_inspections)) # cleanup diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index f11854f52a9..073a3e2d117 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -2258,6 +2258,53 @@ class TestStockEntry(FrappeTestCase): frappe.db.set_single_value("Manufacturing Settings", "material_consumption", original_value) + 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"), + ) + self.assertEqual(qi[0], "NQC-ST-00001") + + # delete naming rule + frappe.delete_doc("Document Naming Rule", qc_naming_rule.name) + def make_serialized_item(**args): args = frappe._dict(args)