From bfb8837c541c35f770df822ca61167c8b7b1eac1 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 29 Nov 2025 12:33:23 +0530 Subject: [PATCH] refactor(test): make bom tests deterministic --- erpnext/manufacturing/doctype/bom/test_bom.py | 5 +++ erpnext/tests/utils.py | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 81391cbd10c..508b9aa012e 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -394,6 +394,7 @@ class TestBOM(ERPNextTestSuite): item_code = make_item(properties={"is_stock_item": 1}).name bom = frappe.new_doc("BOM") + bom.company = self.companies[0].name bom.item = item_code bom.append("items", frappe._dict(item_code=item_code)) bom.save() @@ -407,11 +408,13 @@ class TestBOM(ERPNextTestSuite): item2 = make_item(properties={"is_stock_item": 1}).name bom1 = frappe.new_doc("BOM") + bom1.company = self.companies[0].name bom1.item = item1 bom1.append("items", frappe._dict(item_code=item2)) bom1.save() bom2 = frappe.new_doc("BOM") + bom2.company = self.companies[0].name bom2.item = item2 bom2.append("items", frappe._dict(item_code=item1)) bom2.save() @@ -569,6 +572,7 @@ class TestBOM(ERPNextTestSuite): @timeout def test_clear_inpection_quality(self): bom = frappe.copy_doc(self.globalTestRecords["BOM"][2], ignore_no_copy=True) + bom.company = self.companies[0].name bom.docstatus = 0 bom.is_default = 0 bom.quality_inspection_template = "_Test Quality Inspection Template" @@ -614,6 +618,7 @@ class TestBOM(ERPNextTestSuite): # Step 1: Create BOM bom = frappe.new_doc("BOM") + bom.company = self.companies[0].name bom.item = fg_item.item_code bom.quantity = 1 bom.append( diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index 18a7be0510c..062c18d12d2 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -242,6 +242,8 @@ class ERPNextTestSuite(unittest.TestCase): cls.make_workstation() cls.make_operation() cls.make_bom() + cls.make_quality_inspection_param() + cls.make_quality_inspection_template() cls.update_selling_settings() cls.update_stock_settings() cls.update_system_settings() @@ -2839,6 +2841,48 @@ class ERPNextTestSuite(unittest.TestCase): else: cls.bom.append(frappe.get_doc("BOM", {"item": x.get("item"), "company": x.get("company")})) + @classmethod + def make_quality_inspection_param(cls): + records = [{"doctype": "Quality Inspection Parameter", "parameter": "_Test Param"}] + cls.quality_inspection_param = [] + for x in records: + if not frappe.db.exists("Quality Inspection Parameter", {"parameter": x.get("parameter")}): + cls.quality_inspection_param.append(frappe.get_doc(x).insert()) + else: + cls.quality_inspection_param.append( + frappe.get_doc("Quality Inspection Parameter", {"parameter": x.get("parameter")}) + ) + + @classmethod + def make_quality_inspection_template(cls): + records = [ + { + "quality_inspection_template_name": "_Test Quality Inspection Template", + "doctype": "Quality Inspection Template", + "item_quality_inspection_parameter": [ + { + "specification": cls.quality_inspection_param[0].name, + "doctype": "Item Quality Inspection Parameter", + "parentfield": "item_quality_inspection_parameter", + } + ], + } + ] + cls.quality_inspection_template = [] + for x in records: + if not frappe.db.exists( + "Quality Inspection Template", + {"quality_inspection_template_name": x.get("quality_inspection_template_name")}, + ): + cls.quality_inspection_template.append(frappe.get_doc(x).insert()) + else: + cls.quality_inspection_template.append( + frappe.get_doc( + "Quality Inspection Template", + {"quality_inspection_template_name": x.get("quality_inspection_template_name")}, + ) + ) + @contextmanager def set_user(self, user: str): try: