Hi All,
I am trying to filter the item_code in the production order based on the selected sales order with the below script , but with no success , please help me to debug this code.
frappe.ui.form.on("Production Order", {
item: function(frm) {
frappe.call({
"method": "frappe.client.get_value",
"args": {
"doctype": "Sales Order",
"filters": {"item_code": cur_frm.doc.item},
"fieldname": ["sales_order"]
},
callback: function(r) {
cur_frm.set_query("item_code", "items", function(doc, cdt, cdn){
return {
"filters": {
"sales_order": ["=",r.message.sales_order],
}
}
});
}
});
}
});
Thanks in advance
Even tried the below script , getting error in the console : Uncaught TypeError: Cannot read property āget_fieldā of undefined
frappe.ui.form.on("Production Order", "refresh", function (frm, cdt, cdn) {
frm.set_query("production_item", "item", function () {
return{
filters: {
"sales_order": frm.doc.sales_order
}
}
});
});
Please help
Thanks in advance
Hi @srinivasragav ,
You need to write get_query for item_code with sql query, for example see below code
args: {
doctype: "Account",
fieldname: "account_currency",
filters: { name: me.frm.doc.debit_to },
},
callback: function(r, rt) {
if "description" in searchfields:
columns += """, if(length(tabItem.description) > 40, \
concat(substr(tabItem.description, 1, 40), "..."), description) as description"""
searchfields = searchfields + [
field
for field in [searchfield or "name", "item_code", "item_group", "item_name"]
if not field in searchfields
]
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
if filters and isinstance(filters, dict):
if filters.get("customer") or filters.get("supplier"):
party = filters.get("customer") or filters.get("supplier")
item_rules_list = frappe.get_all(
"Party Specific Item", filters={"party": party}, fields=["restrict_based_on", "based_on_value"]
)
filters_dict = {}
for rule in item_rules_list:
Thanks, Rohit
2 Likes
Try to set set_query
inside āonloadā function.
1 Like
Hi @rohit_w ,
Many thanks for responding , I tried your suggestion but I am getting this error , when I click on the sales order field , AttributeError: āmoduleā object has no attribute āget_sales_orderā
frappe.ui.form.on("Production Order", "refresh", function (frm, cdt, cdn) {
cur_frm.fields_dict['sales_order'].get_query = function(doc, cdt, cdn) {
return{
query: "erpnext.controllers.queries.get_sales_order",
filters: {'production_item': doc.item}
}
}
});
Please help
Hi @nabinhait . Sir I am novice could you please explain me how to do that ?
Thanks
If the refresh function in the above code is removed it does not show any error , but still the list is not getting filtered. Please help