From ee8e96dbcf3d145e7b2cfed6adbc28e7e4d5271e Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 2 Jan 2026 15:53:59 +0530 Subject: [PATCH] refactor(test): make subcontracting order deterministic --- .../tests/test_subcontracting_controller.py | 2 +- .../test_subcontracting_order.py | 7 ++++++- erpnext/tests/utils.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py index 6ee3da7f1a8..03dcc01c5aa 100644 --- a/erpnext/controllers/tests/test_subcontracting_controller.py +++ b/erpnext/controllers/tests/test_subcontracting_controller.py @@ -1560,7 +1560,7 @@ def make_subcontracted_item(**args): }, ) - args.raw_materials = ["_Test FG Item", "Test Extra Item 1"] + args.raw_materials = ["_Test Extra Item 1", "Test Extra Item 2"] if not frappe.db.get_value("BOM", {"item": args.item_code}, "name"): make_bom(item=args.item_code, raw_materials=args.get("raw_materials")) diff --git a/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py b/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py index 0ce5ef4216b..281ded9e4f4 100644 --- a/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_order/test_subcontracting_order.py @@ -40,6 +40,9 @@ class TestSubcontractingOrder(ERPNextTestSuite): make_service_items() make_bom_for_subcontracted_items() + def tearDown(self): + frappe.db.rollback() + def test_set_missing_values(self): sco = get_subcontracting_order() before = {sco.total_qty, sco.total, sco.total_additional_costs} @@ -460,6 +463,7 @@ class TestSubcontractingOrder(ERPNextTestSuite): set_backflush_based_on("BOM") + @ERPNextTestSuite.change_settings("Buying Settings", {"allow_multiple_items": True}) def test_supplied_qty(self): item_code = "_Test Subcontracted FG Item 5" make_item("Sub Contracted Raw Material 4", {"is_stock_item": 1, "is_sub_contracted_item": 1}) @@ -472,7 +476,7 @@ class TestSubcontractingOrder(ERPNextTestSuite): service_items = [ { "warehouse": "_Test Warehouse - _TC", - "item_code": "Subcontracted Service Item 1", + "item_code": "Subcontracted Service Item 2", "qty": order_qty, "rate": 100, "fg_item": item_code, @@ -678,6 +682,7 @@ class TestSubcontractingOrder(ERPNextTestSuite): self.assertEqual(requested_qty, new_requested_qty) + @ERPNextTestSuite.change_settings("System Settings", {"float_precision": 3}) def test_subcontracting_order_rm_required_items_for_precision(self): item_code = "Subcontracted Item SA9" raw_materials = ["Subcontracted SRM Item 9"] diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index eb8ff56f54e..de1a1428e98 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -2157,6 +2157,24 @@ class ERPNextTestSuite(unittest.TestCase): "valuation_rate": 10000, "stock_uom": "_Test UOM", }, + { + "doctype": "Item", + "item_code": "_Test Extra Item 1", + "item_name": "_Test Extra Item 1", + "item_group": "All Item Groups", + "company": "_Test Company", + "is_stock_item": 1, + "stock_uom": "_Test UOM", + }, + { + "doctype": "Item", + "item_code": "_Test Extra Item 2", + "item_name": "_Test Extra Item 2", + "item_group": "All Item Groups", + "company": "_Test Company", + "is_stock_item": 1, + "stock_uom": "_Test UOM", + }, ] cls.item = [] for x in records: