fix: Show 'Bill of Materials' custom button conditionally

This commit is contained in:
marination 2019-11-15 12:03:06 +05:30
parent 075f6ea0d5
commit a076bddd83

View File

@ -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) { if (frm.doc.docstatus===0) {
frm.add_custom_button(__('Purchase Invoice'), function() { frm.add_custom_button(__('Purchase Invoice'), function() {
erpnext.utils.map_current_doc({ erpnext.utils.map_current_doc({
@ -257,6 +251,17 @@ frappe.ui.form.on('Stock Entry', {
frm.trigger("setup_quality_inspection"); 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) { purpose: function(frm) {
frm.trigger('validate_purpose_consumption'); frm.trigger('validate_purpose_consumption');
frm.fields_dict.items.grid.refresh(); 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}, "label":__("Fetch exploded BOM (including sub-assemblies)"), "default":1},
{"fieldname":"fetch", "label":__("Get Items from BOM"), "fieldtype":"Button"} {"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); fields.splice(2,1);
} }
else if(frm.doc.stock_entry_type == 'Material Receipt'){ else if(frm.doc.purpose == 'Material Receipt'){
fields.splice(1,1); fields.splice(1,1);
} }