Filter by "item_group" in child table "item" in quotation

Hi,

Try below code,

frappe.ui.form.on("Quotation", "item_group", function (frm, cdt, cdn) {
    if(frm.doc.__islocal) {
        frappe.call({
            method: "frappe.client.get_list",
            args: {
                doctype: "Item",
                filters: {
                    "item_group": frm.doc.item_group,
                    "is_sales_item": 1
                },
                fields:["item_code", "item_name", "description", "stock_uom"]
            },
            callback: function(r) {
                    var items = [];
                    frm.clear_table("items");
                    for(var i=0; i< r.message.length; i++) {
                        var d = frm.add_child("items");
                        $.extend(d, r.message[i]);
                        if(!d.qty) d.qty = 1;
                        if(!d.uom) d.uom = d.stock_uom;
                    }
                    frm.refresh_field("items");
                }
        })
    }
});

Try with something like…

frappe.ui.form.on("Quotation", "item_group", function(frm) {cur_frm.fields_dict['items'].grid.get_field('item_code').get_query = function(doc) {
		return {
	        	filters: [
			['Item', 'item_group', 'in', doc.item_group]
			]
			}
      };
});

@Francisco_Buendia
not working

@schilgod it is printing all the items without selecting any item_group and customer.
filtering isn’t working, all the item is printed as bellow

updated to “item_group” instead of “onload”, try again please

@schilgod

thanks a ton :blush:

here is final working script

frappe.ui.form.on("Quotation", "item_group", function (frm, cdt, cdn) {
    if(frm.doc.__islocal) {
        frappe.call({
            method: "frappe.client.get_list",
            args: {
                doctype: "Item",
                filters: {
                    "item_group": frm.doc.item_group,
                    "is_sales_item": 1
                },
                fields:["item_code", "item_name", "description", "stock_uom"]
            },
            callback: function(r) {
                    var items = [];
                    frm.clear_table("items");
                    for(var i=0; i< r.message.length; i++) {
                        var d = frm.add_child("items");
                        $.extend(d, r.message[i]);
                        if(!d.qty) d.qty = 1;
                        if(!d.uom) d.uom = d.stock_uom;
                    }
                    frm.refresh_field("items");
                }
        })
    }
});;
4 Likes