Sales Order DocType

hello,
i want to adjust the sales order item table, so when i specify the collection and i want to choose the item code, it will display only the items of this collection in the search.
is that possible? and how?
in other words make the item code based on the specification of the collection

Basically there is two ways

  1. set_query (fixed once applied you can not change filter dynamical)
  2. get query (filter can be changed dynamical )

as sales order is not custom doctype so set_query in normal on_load or change event will not work so try this for set_query

  1.  cur_frm.cscript.onload = function(frm) {
     	cur_frm.set_query("Item_code",function() {
     			return {"query":"your.module.path.method_name",
     		    filters:{'collection':your_filter}}
     	});
     }
    
  2. get query (this should work in normal custom on_load & change event)

    	cur_frm.fields_dict['items'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
    		return {
    			query: "your.module.path.method_name",
    			filters: {'collection':your filter}
    		}
    	}
    

your.module.path.method_name —> is path to your python script from which you are returning a data you can write sql query there like i.e “”“return frappe.db.sql( select item_name from tabItem where collection ={0}”".format(collection))

1 Like

thanks for ur reply, but we cant done this from the system directly? we need to change it from atom?

Yes, you will have to use a custom script to do this. We had similar requirements. We first select the supplier in the first column and then it only shows items available from that supplier in the second column and we select that.

okey, one more question please
filters: {‘collection’:your filter}
here what should i should replace “your filter”??
because my filter has to be choosen by the user not me