Need help in customizing BOM

Hi ,

Could anyone tell me how to do this ?

I want only the items which is in stock to be displayed when I add items to the BOM .

Thanks

You probably can do this with a custom script:

cur_frm.fields_dict[ā€˜itemsā€™].grid.get_field(ā€˜item_codeā€™).get_query = function(doc, cdt, cdn) {
return {
filters:{ā€˜default_supplierā€™: doc.supplier}
}
}

1 Like

@Ben_Cornwell_Mott . Thanks a lot for the help I already read from one of your post https://discuss.frappe.io/t/need-help-customizing-bom/13758 and did changes as per my requirement , but dont know exactly how to make it count the stock available ? Any help ?

Thanks

Looking at it closer, I donā€™t think get_query will work.

I think your best bet is to create a custom query, like the ones in
erpnext/erpnext/controllers/queries.py

Do this server side and you can query using set_query.

1 Like

@Ben_Cornwell_Mott. Thanks for the reply . Server side validation always looks complicated , is there a way that I could achieve this with js ?

Thanks

I havenā€™t seen an example of how to filter a list purely through js, but it likely would be very slow. I started working on some code which derives the list of in stock parts, but I canā€™t get the list to actually filter:

cur_frm.set_query(ā€˜item_codeā€™,ā€œitemsā€, function(frm,cdt,cdn){
console.log(ā€œGot HEREā€);
frappe.call({
method:ā€œerpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_itemsā€,
args: {
warehouse: ā€œStores - VMIā€,
posting_date: ā€œā€,
posting_time: ā€œā€
},
callback: function(r) {
console.log(r);
for (i=r.message.length-1;i >=0; iā€“)
{
if (r.message[i].qty <= 0) {
r.message.splice(i, 1);
}
}
console.log(r);
return r.message;
}
});
}
);

To be clear, the above is not a working solution, but the start of something, maybe. I think server side would be far easier.

1 Like

@Ben_Cornwell_Mott . Thanks a lot for guiding me , I will try and let you know what I have done .

Thanks again