The second task was how to limit the Item Group but to have also parent Item Group with name “(3) This a parent I want” or “(2) This a parent I also want”.
On your app, create: yourapp/yourapp/controllers/init.py
2.On your app, create: yourapp/yourapp/controllers/queries.py
# Limit Item Group to List only leaf tree or (3) or (2)
def group_item_query(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""select name From `tabItem Group`
or name like '(3)%'
or name like '(2)%'""")
Please be aware, that the above solution is an over simplification, meaning you have add some more logic in your database query in order to have the default Link Field functionality like on the fly search. Also, alter query will not be valid if you Quick Entry as True, meaning that in Quick Entry your user will still see the whole list