From a076bddd833e6ec82fbfdf87cbbe0bbee3147368 Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 15 Nov 2019 12:03:06 +0530 Subject: [PATCH] fix: Show 'Bill of Materials' custom button conditionally --- .../stock/doctype/stock_entry/stock_entry.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index cee09e78c6..bb85ef0c48 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -181,12 +181,6 @@ frappe.ui.form.on('Stock Entry', { } } - if (frm.doc.docstatus === 0) { - frm.add_custom_button(__('Bill of Materials'), function(){ - frm.events.get_items_from_bom(frm); - }, __("Get items from")); - } - if (frm.doc.docstatus===0) { frm.add_custom_button(__('Purchase Invoice'), function() { erpnext.utils.map_current_doc({ @@ -257,6 +251,17 @@ frappe.ui.form.on('Stock Entry', { frm.trigger("setup_quality_inspection"); }, + stock_entry_type: function(frm){ + frm.remove_custom_button('Bill of Materials', "Get items from"); + + if (frm.doc.docstatus === 0 && ['Material Issue','Material Receipt', + 'Material Transfer','Send to Subcontractor'].includes(frm.doc.purpose)) { + frm.add_custom_button(__('Bill of Materials'), function(){ + frm.events.get_items_from_bom(frm); + }, __("Get items from")); + } + }, + purpose: function(frm) { frm.trigger('validate_purpose_consumption'); frm.fields_dict.items.grid.refresh(); @@ -411,10 +416,10 @@ frappe.ui.form.on('Stock Entry', { "label":__("Fetch exploded BOM (including sub-assemblies)"), "default":1}, {"fieldname":"fetch", "label":__("Get Items from BOM"), "fieldtype":"Button"} ] - if (frm.doc.stock_entry_type == 'Material Issue'){ + if (frm.doc.purpose == 'Material Issue'){ fields.splice(2,1); } - else if(frm.doc.stock_entry_type == 'Material Receipt'){ + else if(frm.doc.purpose == 'Material Receipt'){ fields.splice(1,1); }