I would like to be able to search in the supplier link field in the supplier invoice page by a custom field in supplier.
The current behavior is that the supplier is searchable by the auto generated name and the actual name which is the first field in the description.
I’d like to search by the field outlined in red in the image below.
I am having trouble hunting down where the actual comparison is made in the source code.
Any help either pointing me towards where the code needs modification, or if there is a setting I am missing somewhere that allows search by the full description string would be highly appreciated.
Thank you, but I’ve already added my custom field to the search fields input. That’s how it shows up in the description line, but the search only searches on supplier_name. No changes I make to the search fields change the way the search is actually performed. If I delete all entries there the supplier is still searched based on the supplier_name and if I only add my custom field it is still searched by supplier_name.
I expected that by adding fields to the search fields input that the supplier would be searchable by any field added, but what is happening is that those fields are visible in the search dialog boxes, but aren’t actually searchable.
I’ve found the solution:
The default query found at erpnext.controllers.queries called supplier_query doesn’t work as expected. It attempts to query for multiple fields using an or condition, but it’s expecting the list of ‘search fields’ to be passed as a parameter.
Instead of trying to figure out how to pass the list as a parameter, I just rewrote the query in my custom app code and copied how the erpnext.controllers.queries.customer_query works. Basically it just looks up the search_fields within the method and appends them to the query as or conditions.
The hard part is to force the purchase invoice page to call the new query when making changes to the supplier field. The official documentation: Overriding Link Query By Custom Script says this can be accomplished in a client script by the following method:
frappe.ui.form.on("Purchase Invoice", "onload", function(frm){
frm.set_query("supplier", function(){
return {
query: "custom_app.customCode.customized_supplier_query"
}
});
});
But I found that the set_query method would not be called for some reason when called in this manner. So in my client script I did this instead and it works:
cur_frm.cscript.onload = function(frm) {
cur_frm.set_query("supplier", function() {
return {
query: "custom_app.customCode.customized_supplier_query"
}
});
}
If anyone happens to know why that would work instead of the more common way of invoking a method “onload” I’d be interested to understand it.
i am also not able to search employee link field by name can you help me??