fix: only auto-set serial nos and batches if allowed in Stock Settings (develop) (#21781)

* fix: only auto-set serial nos and batches if allowed in Stock Settings

* fix: bug with setting disabled batch no in Pick List

* fix: remove auto-set batch variable

Co-authored-by: Marica <maricadsouza221197@gmail.com>
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index 93b29c8..4b8b594 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -119,11 +119,13 @@
 		if item_location.serial_no:
 			serial_nos = '\n'.join(item_location.serial_no[0: cint(stock_qty)])
 
+		auto_set_serial_no = frappe.db.get_single_value("Stock Settings", "automatically_set_serial_nos_based_on_fifo")
+
 		locations.append(frappe._dict({
 			'qty': qty,
 			'stock_qty': stock_qty,
 			'warehouse': item_location.warehouse,
-			'serial_no': serial_nos,
+			'serial_no': serial_nos if auto_set_serial_no else item_doc.serial_no,
 			'batch_no': item_location.batch_no
 		}))
 
@@ -206,6 +208,7 @@
 			sle.batch_no = batch.name
 			and sle.`item_code`=%(item_code)s
 			and sle.`company` = %(company)s
+			and batch.disabled = 0
 			and IFNULL(batch.`expiry_date`, '2200-01-01') > %(today)s
 			{warehouse_condition}
 		GROUP BY
@@ -471,4 +474,4 @@
 	item.material_request = location.material_request
 	item.serial_no = location.serial_no
 	item.batch_no = location.batch_no
-	item.material_request_item = location.material_request_item
\ No newline at end of file
+	item.material_request_item = location.material_request_item