From b77f6168d9433665be060836849a94f65f5ccbbc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 2 Jul 2026 14:05:15 +0530 Subject: [PATCH] test: load BOM fixtures and scope to top-level rows in BOM Explorer test --- .../report/bom_explorer/test_bom_explorer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/report/bom_explorer/test_bom_explorer.py b/erpnext/manufacturing/report/bom_explorer/test_bom_explorer.py index 3a7a1351c5b..54bfae2d6c2 100644 --- a/erpnext/manufacturing/report/bom_explorer/test_bom_explorer.py +++ b/erpnext/manufacturing/report/bom_explorer/test_bom_explorer.py @@ -9,16 +9,26 @@ from erpnext.tests.utils import ERPNextTestSuite class TestBOMExplorer(ERPNextTestSuite): + def setUp(self): + # the tests look up `_Test FG Item`'s BOM, which comes from the BOM fixtures; + # load them so the file also passes when run in isolation + self.load_test_records("BOM") + def run_report(self, bom): filters = frappe._dict({"bom": bom}) return execute(filters)[1] + def top_level_rows_by_item(self, data): + # key only the direct (indent 0) components, so an item that also appears in a + # deeper sub-assembly can't overwrite the top-level row we assert against + return {row["item_code"]: row for row in data if row["indent"] == 0} + def test_default_bom_lists_components_at_top_level(self): bom = frappe.db.get_value("BOM", {"item": "_Test FG Item", "is_active": 1, "is_default": 1}) self.assertIsNotNone(bom, "Default active BOM for _Test FG Item not found") data = self.run_report(bom) - rows_by_item = {row["item_code"]: row for row in data} + rows_by_item = self.top_level_rows_by_item(data) self.assertIn("_Test Item", rows_by_item) self.assertIn("_Test Item Home Desktop 100", rows_by_item) @@ -31,7 +41,7 @@ class TestBOMExplorer(ERPNextTestSuite): def test_qty_matches_bom_item_qty(self): bom = frappe.db.get_value("BOM", {"item": "_Test FG Item", "is_active": 1, "is_default": 1}) data = self.run_report(bom) - rows_by_item = {row["item_code"]: row for row in data} + rows_by_item = self.top_level_rows_by_item(data) for bom_item in frappe.get_all( "BOM Item", filters={"parent": bom}, fields=["item_code", "qty", "uom"]