From 4c39cf2d650207c3d02d1da8490fcf2657ddc488 Mon Sep 17 00:00:00 2001 From: kavin-114 Date: Sat, 28 Feb 2026 16:36:22 +0530 Subject: [PATCH] test: add unit test to handle company condition in naming rule --- .../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 ba95b61cd33..d42a59c5e35 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -2410,6 +2410,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)