From f35710db15d15adc84769abd99f873fa59ce7c0a Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Wed, 16 Aug 2017 08:55:18 +0100 Subject: [PATCH] remove empty first row if needed (#10378) refactor code: move global functions to callback scope --- erpnext/public/js/controllers/buying.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 92ef72540a..010d4d9269 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -346,7 +346,21 @@ erpnext.buying.get_items_from_product_bundle = function(frm) { }, freeze: true, callback: function(r) { + const first_row_is_empty = function(child_table){ + if($.isArray(child_table) && child_table.length > 0) { + return !child_table[0].item_code; + } + return false; + }; + + const remove_empty_first_row = function(frm){ + if (first_row_is_empty(frm.doc.items)){ + frm.doc.items = frm.doc.items.splice(1); + } + }; + if(!r.exc && r.message) { + remove_empty_first_row(frm); for ( var i=0; i< r.message.length; i++ ) { var d = frm.add_child("items"); var item = r.message[i]; @@ -366,3 +380,4 @@ erpnext.buying.get_items_from_product_bundle = function(frm) { }); dialog.show(); } +