@@ -2415,6 +2415,54 @@ def test_validation_as_per_bom_with_continuous_raw_material_consumption(self):
24152415 frappe .get_doc (_make_stock_entry (work_order .name , "Material Consumption for Manufacture" , 5 )).submit ()
24162416 frappe .get_doc (_make_stock_entry (work_order .name , "Manufacture" , 5 )).submit ()
24172417
2418+ def test_qi_creation_with_naming_rule_company_condition (self ):
2419+ """
2420+ Unit test case to check the document naming rule with company condition
2421+ For Quality Inspection, when created from Stock Entry.
2422+ """
2423+ from erpnext .accounts .report .trial_balance .test_trial_balance import create_company
2424+ from erpnext .controllers .stock_controller import make_quality_inspections
2425+ from erpnext .stock .doctype .warehouse .test_warehouse import create_warehouse
2426+
2427+ # create a separate company to handle document naming rule with company condition
2428+ qc_company = create_company (company_name = "Test Quality Company" )
2429+
2430+ # create document naming rule based on that for Quality Inspection Doctype
2431+ qc_naming_rule = frappe .new_doc (
2432+ "Document Naming Rule" , document_type = "Quality Inspection" , prefix = "NQC.-ST-" , prefix_digits = 5
2433+ )
2434+ qc_naming_rule .append ("conditions" , {"field" : "company" , "condition" : "=" , "value" : qc_company })
2435+ qc_naming_rule .save ()
2436+
2437+ warehouse = create_warehouse (warehouse_name = "Test QI Warehouse" , company = qc_company )
2438+ item = create_item (
2439+ item_code = "Test QI DNR Item" ,
2440+ is_stock_item = 1 ,
2441+ )
2442+
2443+ # create inward stock entry
2444+ stock_entry = make_stock_entry (
2445+ item_code = item .item_code ,
2446+ target = warehouse ,
2447+ qty = 10 ,
2448+ basic_rate = 100 ,
2449+ inspection_required = True ,
2450+ do_not_submit = True ,
2451+ )
2452+
2453+ # create QI from Stock Entry and check the naming series generated.
2454+ qi = make_quality_inspections (
2455+ stock_entry .company ,
2456+ stock_entry .doctype ,
2457+ stock_entry .name ,
2458+ stock_entry .as_dict ().get ("items" ),
2459+ "Incoming" ,
2460+ )
2461+ self .assertEqual (qi [0 ], "NQC-ST-00001" )
2462+
2463+ # delete naming rule
2464+ frappe .delete_doc ("Document Naming Rule" , qc_naming_rule .name )
2465+
24182466
24192467def make_serialized_item (self , ** args ):
24202468 args = frappe ._dict (args )
0 commit comments