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,
onload: function(frm) {
// add item, if previous view was item
erpnext.utils.add_item(frm);
// set schedule_date
set_schedule_date(frm);
frm.set_query("warehouse", "items", function(doc) {
return {
filters: {'company': doc.company}
};
});
frm.set_query("set_warehouse", function(doc){
return {
filters: {'company': doc.company}
};
});
frm.set_query("set_from_warehouse", function(doc){
limit %(page_len)s offset %(start)s""".format(
**{"field": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)}
),
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
as_dict=as_dict,
)
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
doctype = "Account"
company_currency = erpnext.get_company_currency(filters.get("company"))
def get_accounts(with_account_type_filter):
account_type_condition = ""
if with_account_type_filter:
account_type_condition = "AND account_type in %(account_types)s"
accounts = frappe.db.sql(
"""
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}
}
});
}
4 Likes