Hi Everyone,
I want to restrict item list in Sales Order.
User Case
- I am having one select type field in Sales Order and Item both are the common field type.
- Apply filter or show item list based on that field type.
Thank You
Hi Everyone,
I want to restrict item list in Sales Order.
User Case
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
this also not worked.
letās see my use case
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))
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
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ā
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.