Prevent Parent Item Group from Selection

How to prevent parent item group from selection when creating and updating item master?

If I understand correctly, you want to disallow “root” or “branch” item groups, but not “leaf” item groups?
For example, from the default setup, “All Item Groups” would be excluded, but “Consumable” would not?

From link query documentation, you want something like:

frappe.ui.form.on("Item", "onload", function(frm) {
    cur_frm.set_query("item_group", function() {
        return {
            "filters": {
                "is_group": 0,
            }
        };
    });
});

Save this as a custom script. It won’t work in the quick entry.

It works, thanks.

I try similar approach for cost_center on Stock Entry but it won’t replicate the results.

frappe.ui.form.on("Stock Entry", "onload", function(frm) {
    cur_frm.set_query("cost_center", function() {
        return {
            "filters": {
                "is_group": 0,
            }
        };
    });
});

Try that. This is a pretty common pattern and once you get a few of them down, they start to make more sense.

That is exactly what I tried and not working. Their differences with the item entry is that the cost_center in stock entry is located on the child table.