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