erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.extend({
** onload: function(doc) {**
** this._super();**
** this.frm.set_query(“item_code”, “items”, function() {**
** return {**
** query: “erpnext.controllers.queries.item_query”**
** }**
** });**
}
I am trying to override the above script query by a custom script, But its not works for me.
I want to filter the items in material request item by item group. I have created a custom field item group in material request doctype.
I have tried with the following query.
frappe.ui.form.on(“Material Request”, “onload”, function(frm) {
cur_frm.set_query(“item_code”,“items”, function() {
return {
“filters”: {
“item_group”: frm.doc.item_group
}
};
});
});
When I have committed the material_request.js code then only its works.
Kindly help how to override the standard query.
Regards,
stock_qty: item.stock_qty,
company: frm.doc.company,
conversion_rate: 1,
name: frm.doc.name,
material_request_type: frm.doc.material_request_type,
plc_conversion_rate: 1,
rate: item.rate,
conversion_factor: item.conversion_factor
}
},
callback: function(r) {
const d = item;
if(!r.exc) {
$.each(r.message, function(k, v) {
if(!d[k]) d[k] = v;
});
}
}
});
},
});
start, page_len]))
if not tax_accounts:
tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
where tabAccount.docstatus!=2 and is_group = 0
and company = %s and `%s` LIKE %s limit %s, %s"""
% ("%s", searchfield, "%s", "%s", "%s"),
(filters.get("company"), "%%%s%%" % txt, start, page_len))
return tax_accounts
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
conditions = []
description_cond = ''
if frappe.db.count('Item', cache=True) < 50000:
# scan description only if items are less than 50000
description_cond = 'or tabItem.description LIKE %(txt)s'
return frappe.db.sql("""select tabItem.name,
if(length(tabItem.item_name) > 40,
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
By default there is a query
on the link field you are trying to apply filter
.
Try applying a query as a python function. Check item_query
e.g.
frappe.ui.form.on("Material Request", "onload", function(frm) {
frm.set_query("item_code","items", function() {
return {
"query" : "custom_app.controllers.queries.custom_item_query",
"filters": {
"item_group": frm.doc.item_group
}
};
});
});
2 Likes
Thank you @revant_one
I have solved the problem with the below code.
cur_frm.cscript.onload = function(frm) {
cur_frm.set_query("item_code", "items", function() {
return {
filters: {"item_group": frm.doc.item_group}
}
});
}
3 Likes