WIP
diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py
index 4a0e89a..6428835 100644
--- a/erpnext/stock/doctype/batch/batch.py
+++ b/erpnext/stock/doctype/batch/batch.py
@@ -123,4 +123,10 @@
 		frappe.msgprint(_('Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement').format(frappe.bold(item_code)))
 		if throw: raise UnableToSelectBatchError
 
+	# oldest_expiry_date = min([batch.expiry_date for batch in batches])
+
+	# for batch in batches:
+	# 	if batch.expiry_date == oldest_expiry_date:
+	# 		batch_no = batch.batch_no
+
 	return batch_no
\ No newline at end of file
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 83c6139..e43325f 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -43,6 +43,7 @@
 		});
 	},
 	refresh: function(frm) {
+		erpnext.select_batch_and_serial_no(frm);
 		if(!frm.doc.docstatus) {
 			frm.add_custom_button(__('Make Material Request'), function() {
 				frappe.model.with_doctype('Material Request', function() {
@@ -76,6 +77,10 @@
 		frm.fields_dict.items.grid.refresh();
 		frm.cscript.toggle_related_fields(frm.doc);
 	},
+	before_save: function(frm) {
+		console.log("before_save");
+		erpnext.select_batch_and_serial_no(frm);
+	},
 	company: function(frm) {
 		if(frm.doc.company) {
 			var company_doc = frappe.get_doc(":Company", frm.doc.company);
@@ -544,33 +549,54 @@
 });
 
 erpnext.select_batch_and_serial_no = (frm) => {
-	frm.items.forEach(function(d) {
-		if(d.has_batch_no && !d.batch_no) {
-			show_modal(item_code, qty);
-		}
-	});
 
 	let show_modal = (item_code, qty) => {
 		let d = new frappe.ui.Dialog({
 			fields: [
 				{fieldname: 'item_code', read_only: 1, fieldtype:'Link', options: 'Item',
 					label: __('Item Code'), 'default': item_code},
+				{fieldtype:'Column Break'},
 				{fieldname: 'qty', fieldtype:'Float', label: __('Qty'), 'default': qty},
+				{fieldtype:'Section Break'},
 				{fieldname: 'batches', fieldtype: 'Table',
 					fields: [
-						{fieldtype:'Link', fieldname:'batch_no', options: 'Batch', reqd: 1,
+						{fieldtype:'Link', fieldname:'batch_no', options: 'Batch',
 							label: __('Select Batch'), in_list_view:1, get_query: function(doc) {
 								return {filters: {item: item_code }};
 							}},
-						{fieldtype:'Float', fieldname:'available_qty', reqd: 1,
+						{fieldtype:'Float', fieldname:'available_qty',
 							label: __('Available'), in_list_view:1},
-						{fieldtype:'Float', fieldname:'selected_qty', reqd: 1,
+						{fieldtype:'Float', fieldname:'selected_qty',
 							label: __('Qty'), in_list_view:1},
 					],
+					get_data: function() {
+						console.log("in get data");
+						return [
+							{
+
+							},
+							{
+
+							},
+							{
+
+							}
+						]
+					}
 				}
 			]
 		});
+
+		d.show();
 	}
 
+	show_modal("_Test FG Item", 1);
+
+	// frm.doc.items.forEach(function(d) {
+	// 	if(d.has_batch_no && !d.batch_no) {
+	// 		show_modal(d.item_code, d.qty);
+	// 	}
+	// });
+
 
 }
\ No newline at end of file