[minor] Show item quantity in warehouse set query

This commit is contained in:
suyashphadtare 2017-01-12 17:49:37 +05:30
parent cc2c7649a8
commit 049a88cc40
5 changed files with 49 additions and 9 deletions

View File

@ -348,3 +348,30 @@ def get_expense_account(doctype, txt, searchfield, start, page_len, filters):
'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 = []
response = frappe.db.sql("""select distinct `tabWarehouse`.name,
CONCAT_WS(" : ", "Actual Qty", ifnull(round(`tabBin`.actual_qty, 2), 0))
from `tabWarehouse` INNER JOIN `tabBin`
on `tabWarehouse`.name = `tabBin`.warehouse
where
`tabWarehouse`.`{key}` like %(txt)s
{fcond} {mcond}
order by
`tabWarehouse`.name, `tabBin`.actual_qty desc
limit
%(start)s, %(page_len)s """.format(
key=frappe.db.escape(searchfield),
fcond=get_filters_cond(doctype, filters, conditions),
mcond=get_match_cond(doctype)
),
{
"txt": "%%%s%%" % frappe.db.escape(txt),
"start": start,
"page_len": page_len,
})
return response

View File

@ -133,3 +133,19 @@ erpnext.queries.setup_queries = function(frm, options, query_fn) {
set_query(df.options, df.fieldname);
});
}
/* if item code is selected in child table
then list down warehouses with its quantity
else apply default filters.
*/
erpnext.queries.setup_warehouse_query = function(frm){
frm.set_query('warehouse', '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
});
}

View File

@ -24,6 +24,8 @@ frappe.ui.form.on("Sales Order", {
// formatter for material request item
frm.set_indicator_formatter('item_code',
function(doc) { return (doc.qty<=doc.delivered_qty) ? "green" : "orange" })
erpnext.queries.setup_warehouse_query(frm);
}
});

View File

@ -13,14 +13,7 @@ frappe.ui.form.on("Delivery Note", {
return (doc.docstatus==1 || doc.qty<=doc.actual_qty) ? "green" : "orange"
})
frm.set_query("warehouse", "items", function() {
return {
filters: [
["Warehouse", "company", "in", ["", cstr(frm.doc.company)]],
["Warehouse", "is_group", "=", 0]
]
}
})
erpnext.queries.setup_warehouse_query(frm);
}
});

View File

@ -655,7 +655,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-11-07 05:06:39.128312",
"modified": "2017-01-12 16:08:01.207466",
"modified_by": "Administrator",
"module": "Stock",
"name": "Warehouse",
@ -791,7 +791,9 @@
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"search_fields": "",
"sort_order": "DESC",
"title_field": "warehouse_name",
"track_changes": 0,
"track_seen": 0
}