vijaywm
February 27, 2018, 6:45am
1
Using set_query or in any other way, is it possible to customise the displayed value in the awesomeplete dropdowns ?
Use case:
In Stock Entry, if the Source Warehouse is already selected, I would like to display list of items in the selected warehouse and include the balance stock qty along with the item name and description.
Did you try writing a custom query like :
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import json
from collections import defaultdict
import frappe
from frappe import scrub
from frappe.desk.reportview import get_filters_cond, get_match_cond
from frappe.utils import nowdate, unique
import erpnext
from erpnext.stock.get_item_details import _get_item_tax_template
# searches for active employees
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def employee_query(doctype, txt, searchfield, start, page_len, filters):
This file has been truncated. show original
use in Custom Script
/ JS
frm.fields_dict.items.grid.get_field('child_field').get_query = function() {
return {
filters: { ... },
query: "path.to.method"
}
}
vijaywm
February 27, 2018, 2:39pm
3
The Stock Entry use case is not required now.
Thanks revant_one, found a query I was looking for, to get the balance stock qty warehouse wise for selected item. May be better to filter warehouses and bring only warehouses with qty > 0
and tabAccount.{key} LIKE %(txt)s
{condition} {match_condition}"""
.format(condition=condition, key=frappe.db.escape(searchfield),
match_condition=get_match_cond(doctype)), {
'company': filters.get("company", ""),
'txt': "%%%s%%" % frappe.db.escape(txt)
})
@frappe.whitelist()
def warehouse_query(doctype, txt, searchfield, start, page_len, filters):
# Should be used when item code is passed in filters.
conditions, bin_conditions = [], []
filter_dict = get_doctype_wise_filters(filters)
sub_query = """ select round(`tabBin`.actual_qty, 2) from `tabBin`
where `tabBin`.warehouse = `tabWarehouse`.name
{bin_conditions} """.format(
bin_conditions=get_filters_cond(doctype, filter_dict.get("Bin"),
bin_conditions, ignore_permissions=True))
frappe.ui.form.on("Production Order",{
onload : function(frm){
frm.set_query('source_warehouse', 'required_items', function(doc, cdt, cdn) {
var row = locals[cdt][cdn];
var filters = erpnext.queries.warehouse(frm.doc);
if(row.item_code){
$.extend(filters, {"query":"erpnext.controllers.queries.warehouse_query"});
filters["filters"].push(["Bin", "item_code", "=", row.item_code]);
}
return filters
});
}
Actual Qty is displayed with the warehouse description.
So the way to bring extra attributes in the dropdown label is to write a custom query and construct the descrtiption field as required.