From be88d0f8a359c7e2ff8b40e5a3eb34014ff497dd Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 3 Dec 2019 18:13:39 +0530 Subject: [PATCH] fix: Custom button conditionally visible in draft condition as well --- .../stock/doctype/stock_entry/stock_entry.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 96e74ccca1..5c8efcbc01 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -238,6 +238,8 @@ frappe.ui.form.on('Stock Entry', { }, __("Get items from")); } + frm.events.show_bom_custom_button(frm); + if (frm.doc.company) { frm.trigger("toggle_display_account_head"); } @@ -253,13 +255,7 @@ frappe.ui.form.on('Stock Entry', { 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")); - } + frm.events.show_bom_custom_button(frm); }, purpose: function(frm) { @@ -398,6 +394,15 @@ frappe.ui.form.on('Stock Entry', { } }, + show_bom_custom_button: function(frm){ + 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")); + } + }, + get_items_from_bom: function(frm) { let filters = function(){ return {filters: { docstatus:1 }}; @@ -417,11 +422,11 @@ frappe.ui.form.on('Stock Entry', { {"fieldname":"fetch", "label":__("Get Items from BOM"), "fieldtype":"Button"} ] - //Exclude field 'Target Warehouse' in case of Material Issue + // Exclude field 'Target Warehouse' in case of Material Issue if (frm.doc.purpose == 'Material Issue'){ fields.splice(2,1); } - //Exclude field 'Source Warehouse' in case of Material Receipt + // Exclude field 'Source Warehouse' in case of Material Receipt else if(frm.doc.purpose == 'Material Receipt'){ fields.splice(1,1); }