minor changes
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index c70cfcd..31a3f6c 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -198,7 +198,6 @@
 
 					if self.get("is_subcontracted"):
 						args["is_subcontracted"] = self.is_subcontracted
-
 					ret = get_item_details(args)
 
 					for fieldname, value in ret.items():
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 3da28a8..102090b 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -304,7 +304,6 @@
 			this.frm.doc.doctype === 'Delivery Note') {
 			show_batch_dialog = 1;
 		}
-
 		// clear barcode if setting item (else barcode will take priority)
 		if(!from_barcode) {
 			item.barcode = null;
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 0e60179..a9ac8c4 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -69,7 +69,7 @@
 						"get_query": function () {
 							return {
 								filters: {
-									item_code:grid_row.doc.item_code ,
+									item_code:grid_row.doc.item_code,
 									warehouse:cur_frm.doc.is_return ? null : grid_row.doc.warehouse
 								}
 							}
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index e361711..bcef472 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -76,7 +76,6 @@
 			args[key] = value
 
 	out.update(get_pricing_rule_for_item(args))
-
 	if (args.get("doctype") == "Delivery Note" or
 		(args.get("doctype") == "Sales Invoice" and args.get('update_stock'))) \
 		and out.warehouse and out.stock_qty > 0:
@@ -86,8 +85,12 @@
 			actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code)
 			if actual_batch_qty:
 				out.update(actual_batch_qty)
-		
-		if out.has_serial_no:
+
+		if out.has_serial_no and args.get('batch_no'):
+			out.batch_no = args.get('batch_no')
+			out.serial_no = get_serial_no(out, args.serial_no)
+
+		elif out.has_serial_no:
 			out.serial_no = get_serial_no(out, args.serial_no)
 
 	if args.transaction_date and item.lead_time_days:
@@ -468,7 +471,7 @@
 def get_serial_no_batchwise(args):
 	if frappe.db.get_single_value("Stock Settings", "automatically_set_serial_nos_based_on_fifo"):
 		return "\n".join(frappe.db.sql_list("""select name from `tabSerial No`
-			where item_code=%(item_code)s and warehouse=%(warehouse)s and batch_no=%(batch_no)s
+			where item_code=%(item_code)s and warehouse=%(warehouse)s and (batch_no=%(batch_no)s or batch_no is NULL)
 			order by timestamp(purchase_date, purchase_time) asc limit %(qty)s""", {
 				"item_code": args.item_code,
 				"warehouse": args.warehouse,
@@ -688,14 +691,13 @@
 
 	if args.get('warehouse') and args.get('stock_qty') and args.get('item_code'):
 		has_serial_no = frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no")
-
 		if args.get('batch_no') and has_serial_no == 1:
 			return get_serial_no_batchwise(args)
-		# elif (args.get('has_batch_no') == 1) and has_serial_no == 1 and not args.get(batch_no):
+		# elif (args.get('has_batch_no') == 1) and has_serial_no == 1 and not args.get('batch_no'):
 		# 	args.batch_no = get_batch_no(args.item_code, args.warehouse, args.qty)
-		# 	actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code)
+		# 	actual_batch_qty = get_batch_qty(args.batch_no, args.warehouse, args.item_code)
 		# 	if actual_batch_qty:
-		# 		out.update(actual_batch_qty)
+		# 		args.update(actual_batch_qty)
 		# 	return get_serial_no_batchwise(args)
 		elif has_serial_no == 1:
 			args = json.dumps({"item_code": args.get('item_code'),"warehouse": args.get('warehouse'),"stock_qty": args.get('stock_qty')})