diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index a04c652104..59fdf703a3 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -66,27 +66,41 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ }); } + if(this.frm.fields_dict["packed_items"].grid.get_field('batch_no')) { + this.frm.set_query("batch_no", "packed_items", function(doc, cdt, cdn) { + return me.set_query_for_batch(doc, cdt, cdn) + }); + } + if(this.frm.fields_dict["items"].grid.get_field('batch_no')) { this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); - if(!item.item_code) { - frappe.throw(__("Please enter Item Code to get batch no")); - } else { - filters = { - 'item_code': item.item_code, - 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(), - } - if(item.warehouse) filters["warehouse"] = item.warehouse - - return { - query : "erpnext.controllers.queries.get_batch_no", - filters: filters - } - } + return me.set_query_for_batch(doc, cdt, cdn) }); } }, + set_query_for_batch: function(doc, cdt, cdn) { + // Show item's batches in the dropdown of batch no + + var me = this; + var item = frappe.get_doc(cdt, cdn); + + if(!item.item_code) { + frappe.throw(__("Please enter Item Code to get batch no")); + } else { + filters = { + 'item_code': item.item_code, + 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(), + } + if(item.warehouse) filters["warehouse"] = item.warehouse + + return { + query : "erpnext.controllers.queries.get_batch_no", + filters: filters + } + } + }, + refresh: function() { this._super(); this.frm.toggle_display("customer_name", diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index 2078eebded..09affe0494 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -16,7 +16,7 @@ class PackedItem(Document): def get_product_bundle_items(item_code): return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom, t1.description from `tabProduct Bundle Item` t1, `tabProduct Bundle` t2 - where t2.new_item_code=%s and t1.parent = t2.name""", item_code, as_dict=1) + where t2.new_item_code=%s and t1.parent = t2.name order by t1.idx""", item_code, as_dict=1) def get_packing_item_details(item): return frappe.db.sql("""select item_name, description, stock_uom from `tabItem`