diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index a025ff740c6..d3acd5f788d 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -170,6 +170,7 @@ class BOM(WebsiteGenerator): frappe.throw(_("Please select a Company first."), title=_("Mandatory")) self.clear_operations() + self.clear_inspection() self.validate_main_item() self.validate_currency() self.set_conversion_rate() @@ -425,6 +426,10 @@ class BOM(WebsiteGenerator): if not self.with_operations: self.set('operations', []) + def clear_inspection(self): + if not self.inspection_required: + self.set('quality_inspection_template', None) + def validate_main_item(self): """ Validate main FG item""" item = self.get_item_det(self.item) diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 4417123178c..fe6cb0b9c99 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -26,6 +26,9 @@ class TestBOM(FrappeTestCase): if not frappe.get_value('Item', '_Test Item'): make_test_records('Item') + if not frappe.get_value('Quality Inspection Template', '_Test Quality Inspection Template'): + make_test_records('Quality Inspection_Template') + def test_get_items(self): from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict items_dict = get_bom_items_as_dict(bom=get_default_bom(), @@ -495,6 +498,22 @@ class TestBOM(FrappeTestCase): self.assertNotEqual(amendment.name, version.name) self.assertEqual(int(version.name.split("-")[-1]), 2) + def test_clear_inpection_quality(self): + + bom = frappe.copy_doc(test_records[2]) + bom.is_active = 0 + bom.quality_inspection_template = "_Test Quality Inspection Template" + bom.inspection_required = 1 + bom.save() + + self.assertEqual(bom.quality_inspection_template, '_Test Quality Inspection Template') + + bom.inspection_required = 0 + bom.save() + bom.load_from_db() + + self.assertEqual(bom.quality_inspection_template, None) + def get_default_bom(item_code="_Test FG Item 2"): return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1}) diff --git a/erpnext/stock/doctype/quality_inspection_template/test_records.json b/erpnext/stock/doctype/quality_inspection_template/test_records.json new file mode 100644 index 00000000000..a1b6415b54e --- /dev/null +++ b/erpnext/stock/doctype/quality_inspection_template/test_records.json @@ -0,0 +1,12 @@ +[ + { + "quality_inspection_template_name" : "_Test Quality Inspection Template", + "item_quality_inspection_parameter" : [ + { + "specification": "_Test Param", + "doctype": "Item Quality Inspection Parameter", + "parentfield": "item_quality_inspection_parameter" + } + ] + } +]