diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 3a0bcf6b47ef..4b52859cabd9 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -255,15 +255,6 @@ frappe.ui.form.on("BOM", { }); } - if (!skip_qty_field) { - fields.push({ - fieldtype: "Check", - label: __("Use Multi-Level BOM"), - fieldname: "use_multi_level_bom", - default: 1, - }); - } - if (!skip_qty_field) { fields.push({ fieldtype: "Float", @@ -291,6 +282,13 @@ frappe.ui.form.on("BOM", { cur_dialog.refresh(); }, }); + + fields.push({ + fieldtype: "Check", + label: __("Use Multi-Level BOM"), + fieldname: "use_multi_level_bom", + default: frm.doc?.__onload.use_multi_level_bom, + }); } var has_template_rm = frm.doc.items.filter((d) => d.has_variants === 1) || []; diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 730ff494801b..78b95f2c80c0 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -214,6 +214,23 @@ def get_index_for_bom(self, existing_boms): return index + def onload(self): + super().onload() + + self.set_onload_for_muulti_level_bom() + + def set_onload_for_muulti_level_bom(self): + use_multi_level_bom = frappe.db.get_value( + "Property Setter", + {"field_name": "use_multi_level_bom", "doc_type": "Work Order", "property": "default"}, + "value", + ) + + if use_multi_level_bom is None: + use_multi_level_bom = 1 + + self.set_onload("use_multi_level_bom", cint(use_multi_level_bom)) + @staticmethod def get_next_version_index(existing_boms: list[str]) -> int: # split by "/" and "-"