fix: Show 'Bill of Materials' custom button conditionally
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index cee09e7..bb85ef0 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -181,12 +181,6 @@
}
}
- 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 @@
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 @@
"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);
}