Filter Item List in Sales Order

Hi Everyone,

I want to restrict item list in Sales Order.

User Case

  1. I am having one select type field in Sales Order and Item both are the common field type.
  2. Apply filter or show item list based on that field type.

Thank You

use this in JS
cur_frm.fields_dict[‘items’].grid.get_field(“item”).get_query = function(frm,cdt,cdn){
var d = locals[cdt][cdn];
var field = frm.field;
return {
filters:{ “field”: field }
}
}

Hi @nouman
not worked.

frappe.ui.form.on(‘Sales Order’, ‘onload’, function(frm,cdt, cdn) {
cur_frm.fields_dict[‘items’].grid.get_field(“item”).get_query = function(frm,cdt,cdn){
var d = locals[cdt][cdn];
var risk = cur_frm.risk_appetite;
return {
filters:{ “risk_appetite”: risk }
}
}
});

Try this one

cur_frm.cscript.onload = function(frm) {
cur_frm.set_query(“item”,function() {
return{
filters:{ “risk_appetite”: risk }
}
});
}

Run this script outside frappe.ui.form.on

Hi @AkshayJadhao

this also not worked.
let’s see my use case

  1. In Sales Order one field is Risk Appetite.
  2. Same Field is in Item also.

let’s suppose sales order field value is Low then in item table filter the below conditions

Low == Low (correct In this condition user select the particular item )
Low == Medium (Incorrect i mean user not select the item )
Low == High(Incorrect same as above)
Low == Moderately High (same as above)

… e.t.c

filters:{ “risk_appetite”: frm.doc.risk }

if this not work too then try this one (write your sql query in python script to return data )

cur_frm.cscript.onload = function(frm) {
cur_frm.set_query(“Item_code”,function() {
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

but have no access of backend.

i am trying to do using custom script.

I am trying to do on this way.


cur_frm.add_fetch(‘customer’,‘risk_appetite’,‘risk_appetite’)
frappe.ui.form.on(‘Sales Order Item’, ‘item_code’, function(frm,cdt, cdn) {
var service_risk=[];
var risk=cur_frm.doc.risk_appetite;
alert(‘here i am’);
frappe.call({
‘method’: ‘frappe.client.get_list’,
args: {
doctype: “Item”,
fields: ‘risk_appetite’,
filters: {
item_code: cur_frm.doc.item_code,
}
},

async: false,
	callback: function(r) {
	service_risk=r.message[0][service_risk];
	console.log(service_risk);

	// Case-1
	if(service_risk=='Low'){
		alert('coming here')
		//frappe.set_route("List", "Customer")
	}
	
	// Case-2
	else if(service_risk=='Medium'){
		alert('coming here')
		//frappe.set_route("List", "Customer")
	}
	// Case-3
	else if(service_risk=='High'){
		alert('coming here')
		//frappe.set_route("List", "Customer")
	}
	// Case-4
	else if(service_risk=='Moderately High'){
		alert('coming here')
		//frappe.set_route("List", "Customer")
	}
	
	}
});	

});

frappe.ui.form.on(“Sales Order”,{

});

cur_frm.cscript.onload = function(frm) {
cur_frm.set_query(“item_code”,function() {
return {“query”:“my_method.path”,
filters:{‘user_role’:get_user_role()}}
});

}

this worked for me kindly not where i have written this script i have writen this outside the custom script

@AkshayJadhao
but this not worked for me. and i am using custom script.

Please Help !

@hari.kishor where you able to fix this ?

hello every one

here is my user scenario

when i want create sales order and i click on the sales order item table

it shows all the item in the item manager

is there a way it can show only the list of items in my preferred item group “Car”

@AkshayJadhao @nouman @Alaa_Badri

i would appreciate any idea on this as this feature would help restrict employees using the selling module from using procurement item

Hi @Chibuzor_Derrick, in Item you can select “Is Sales Item” and/or “Is Purchase Item”. This has exactly this effect: you can only sell sales items, you can only buy purchase items.

1 Like

works perfectly well for me
thanks @rmeyer