-- This Parent
-- this children1
-- this children2
-- This Parent 2
-- this children 3
-- this children 4
How we can display only children then user data entries a new Item ?
Also consider that Item is core ERPnext DocType, so we need the process can be done with Custom Form or Custom Script in order to version control it with export-fixtures.
Enter only children leaf node items as item record. And other group Items should be entered as Item Group record. Item and Item Group are separate doctype in erpnext.
If you are doing custom sql query refer lead_query example from above link.
you have to use all arguments viz doctype, txt, searchfield, start, page_len, filters. Only then the auto-complete and filtering as you type in link field will work.
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”.
So,
On your app, create: yourapp/yourapp/controllers/init.py
2.On your app, create: yourapp/yourapp/controllers/queries.py
in queries.py
import frappe
# 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`
where
is_group=0
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