[Serial No] Major updates, code cleanup, "In Store" is now "Available". Serial No can only be created via Stock Entry / Purchase Receipt. Serial No can be auto created using Series if mentioned in Item master
diff --git a/selling/utils.py b/selling/utils.py
index 7ccad6a..86b1b9d 100644
--- a/selling/utils.py
+++ b/selling/utils.py
@@ -70,9 +70,22 @@
 	if cint(args.is_pos):
 		pos_settings = get_pos_settings(args.company)
 		out.update(apply_pos_settings(pos_settings, out))
-
+		
+	if args.doctype in ("Sales Invoice", "Delivery Note"):
+		if item_bean.doc.has_serial_no and not args.serial_no:
+			out.serial_no = _get_serial_nos_by_fifo(args, item_bean)
+		
 	return out
-	
+
+def _get_serial_nos_by_fifo(args, item_bean):
+	return "\n".join(webnotes.conn.sql_list("""select name from `tabSerial No` 
+		where item_code=%(item_code)s and warehouse=%(warehouse)s and status='Available' 
+		order by datetime(purchase_date, purchase_time) asc limit %(qty)s""" % {
+			"item_code": args.item_code,
+			"warehouse": args.warehouse,
+			"qty": cint(args.qty)
+		}))
+
 def _get_item_code(barcode):
 	item_code = webnotes.conn.sql_list("""select name from `tabItem` where barcode=%s""", barcode)