fix(ux): move `get_route_options_for_new_doc` to `refresh` (#37096)

fix: move `get_route_options_for_new_doc` to `refresh`
diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.js b/erpnext/assets/doctype/asset_repair/asset_repair.js
index dae993a..03afcb9 100644
--- a/erpnext/assets/doctype/asset_repair/asset_repair.js
+++ b/erpnext/assets/doctype/asset_repair/asset_repair.js
@@ -40,16 +40,6 @@
 				}
 			}
 		});
-
-		let sbb_field = frm.get_docfield('stock_items', 'serial_and_batch_bundle');
-		if (sbb_field) {
-			sbb_field.get_route_options_for_new_doc = (row) => {
-				return {
-					'item_code': row.doc.item_code,
-					'voucher_type': frm.doc.doctype,
-				}
-			};
-		}
 	},
 
 	refresh: function(frm) {
@@ -61,6 +51,16 @@
 				frappe.set_route("query-report", "General Ledger");
 			});
 		}
+
+		let sbb_field = frm.get_docfield('stock_items', 'serial_and_batch_bundle');
+		if (sbb_field) {
+			sbb_field.get_route_options_for_new_doc = (row) => {
+				return {
+					'item_code': row.doc.item_code,
+					'voucher_type': frm.doc.doctype,
+				}
+			};
+		}
 	},
 
 	repair_status: (frm) => {
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.js b/erpnext/manufacturing/doctype/job_card/job_card.js
index f1e6094..6621275 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.js
+++ b/erpnext/manufacturing/doctype/job_card/job_card.js
@@ -23,17 +23,6 @@
 			}
 		});
 
-		let sbb_field = frm.get_docfield('serial_and_batch_bundle');
-		if (sbb_field) {
-			sbb_field.get_route_options_for_new_doc = () => {
-				return {
-					'item_code': frm.doc.production_item,
-					'warehouse': frm.doc.wip_warehouse,
-					'voucher_type': frm.doc.doctype,
-				}
-			};
-		}
-
 		frm.set_indicator_formatter('sub_operation',
 			function(doc) {
 				if (doc.status == "Pending") {
@@ -124,6 +113,17 @@
 				}
 			});
 		}
+
+		let sbb_field = frm.get_docfield('serial_and_batch_bundle');
+		if (sbb_field) {
+			sbb_field.get_route_options_for_new_doc = () => {
+				return {
+					'item_code': frm.doc.production_item,
+					'warehouse': frm.doc.wip_warehouse,
+					'voucher_type': frm.doc.doctype,
+				}
+			};
+		}
 	},
 
 	setup_quality_inspection: function(frm) {
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 80d7b79..975adc2 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -134,15 +134,6 @@
 					}
 				}
 			});
-
-			let sbb_field = this.frm.get_docfield('items', 'serial_and_batch_bundle');
-			if (sbb_field) {
-				sbb_field.get_route_options_for_new_doc = (row) => {
-					return {
-						'item_code': row.doc.item_code,
-					}
-				};
-			}
 		}
 
 		if(
@@ -207,15 +198,6 @@
 			});
 		}
 
-		let batch_no_field = this.frm.get_docfield("items", "batch_no");
-		if (batch_no_field) {
-			batch_no_field.get_route_options_for_new_doc = function(row) {
-				return {
-					"item": row.doc.item_code
-				}
-			};
-		}
-
 		if (this.frm.fields_dict["items"].grid.get_field('blanket_order')) {
 			this.frm.set_query("blanket_order", "items", function(doc, cdt, cdn) {
 				var item = locals[cdt][cdn];
@@ -268,6 +250,28 @@
 				}
 			]);
 		}
+
+		if(this.frm.fields_dict['items'].grid.get_field('serial_and_batch_bundle')) {
+			let sbb_field = this.frm.get_docfield('items', 'serial_and_batch_bundle');
+			if (sbb_field) {
+				sbb_field.get_route_options_for_new_doc = (row) => {
+					return {
+						'item_code': row.doc.item_code,
+					}
+				};
+			}
+		}
+
+		if(this.frm.fields_dict['items'].grid.get_field('batch_no')) {
+			let batch_no_field = this.frm.get_docfield('items', 'batch_no');
+			if (batch_no_field) {
+				batch_no_field.get_route_options_for_new_doc = function(row) {
+					return {
+						'item': row.doc.item_code
+					}
+				};
+			}
+		}
 	}
 
 	is_return() {
@@ -358,7 +362,6 @@
 	}
 
 	refresh() {
-
 		erpnext.toggle_naming_series();
 		erpnext.hide_company();
 		this.set_dynamic_labels();
diff --git a/erpnext/selling/doctype/installation_note/installation_note.js b/erpnext/selling/doctype/installation_note/installation_note.js
index dd6f8a8..8128c77 100644
--- a/erpnext/selling/doctype/installation_note/installation_note.js
+++ b/erpnext/selling/doctype/installation_note/installation_note.js
@@ -18,6 +18,14 @@
 				}
 			}
 		});
+	},
+	onload: function(frm) {
+		if(!frm.doc.status) {
+			frm.set_value({ status:'Draft'});
+		}
+		if(frm.doc.__islocal) {
+			frm.set_value({inst_date: frappe.datetime.get_today()});
+		}
 
 		let sbb_field = frm.get_docfield('items', 'serial_and_batch_bundle');
 		if (sbb_field) {
@@ -29,14 +37,6 @@
 			};
 		}
 	},
-	onload: function(frm) {
-		if(!frm.doc.status) {
-			frm.set_value({ status:'Draft'});
-		}
-		if(frm.doc.__islocal) {
-			frm.set_value({inst_date: frappe.datetime.get_today()});
-		}
-	},
 	customer: function(frm) {
 		erpnext.utils.get_party_details(frm);
 	},
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index d18f70a..1bc8d68 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -48,6 +48,11 @@
 				}
 			}
 		});
+	},
+
+	refresh: function(frm) {
+		frm.trigger("set_label");
+		frm.trigger("set_dynamic_field_label");
 
 		let sbb_field = frm.get_docfield('packed_items', 'serial_and_batch_bundle');
 		if (sbb_field) {
@@ -61,11 +66,6 @@
 		}
 	},
 
-	refresh: function(frm) {
-		frm.trigger("set_label");
-		frm.trigger("set_dynamic_field_label");
-	},
-
 	quotation_to: function(frm) {
 		frm.trigger("set_label");
 		frm.trigger("toggle_reqd_lead_customer");
diff --git a/erpnext/stock/doctype/pick_list/pick_list.js b/erpnext/stock/doctype/pick_list/pick_list.js
index 4eed285..ae05b80 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.js
+++ b/erpnext/stock/doctype/pick_list/pick_list.js
@@ -65,17 +65,6 @@
 				}
 			}
 		});
-
-		let sbb_field = frm.get_docfield('locations', 'serial_and_batch_bundle');
-		if (sbb_field) {
-			sbb_field.get_route_options_for_new_doc = (row) => {
-				return {
-					'item_code': row.doc.item_code,
-					'warehouse': row.doc.warehouse,
-					'voucher_type': frm.doc.doctype,
-				}
-			};
-		}
 	},
 	set_item_locations:(frm, save) => {
 		if (!(frm.doc.locations && frm.doc.locations.length)) {
@@ -132,6 +121,17 @@
 				}
 			}
 		}
+
+		let sbb_field = frm.get_docfield('locations', 'serial_and_batch_bundle');
+		if (sbb_field) {
+			sbb_field.get_route_options_for_new_doc = (row) => {
+				return {
+					'item_code': row.doc.item_code,
+					'warehouse': row.doc.warehouse,
+					'voucher_type': frm.doc.doctype,
+				}
+			};
+		}
 	},
 	work_order: (frm) => {
 		frappe.db.get_value('Work Order',
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 4fb8a10..d37e8ee 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -117,15 +117,6 @@
 			}
 		});
 
-		let sbb_field = frm.get_docfield('items', 'serial_and_batch_bundle');
-		if (sbb_field) {
-			sbb_field.get_route_options_for_new_doc = (row) => {
-				return {
-					'item_code': row.doc.item_code,
-					'voucher_type': frm.doc.doctype,
-				}
-			};
-		}
 
 		frm.add_fetch("bom_no", "inspection_required", "inspection_required");
 		erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
@@ -362,6 +353,16 @@
 		if(!check_should_not_attach_bom_items(frm.doc.bom_no)) {
 			erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
 		}
+
+		let sbb_field = frm.get_docfield('items', 'serial_and_batch_bundle');
+		if (sbb_field) {
+			sbb_field.get_route_options_for_new_doc = (row) => {
+				return {
+					'item_code': row.doc.item_code,
+					'voucher_type': frm.doc.doctype,
+				}
+			};
+		}
 	},
 
 	get_items_from_transit_entry: function(frm) {
diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js
index 8ac22e6..19a1c93 100644
--- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js
+++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js
@@ -77,6 +77,7 @@
 		}
 
 		frm.trigger('setup_quality_inspection');
+		frm.trigger('set_route_options_for_new_doc');
 	},
 
 	set_warehouse: (frm) => {
@@ -87,6 +88,23 @@
 		set_warehouse_in_children(frm.doc.items, 'rejected_warehouse', frm.doc.rejected_warehouse);
 	},
 
+	get_scrap_items: (frm) => {
+		frappe.call({
+			doc: frm.doc,
+			method: 'get_scrap_items',
+			args: {
+				recalculate_rate: true
+			},
+			freeze: true,
+			freeze_message: __('Getting Scrap Items'),
+			callback: (r) => {
+				if (!r.exc) {
+					frm.refresh();
+				}
+			}
+		});
+	},
+
 	set_queries: (frm) => {
 		frm.set_query('set_warehouse', () => {
 			return {
@@ -173,7 +191,28 @@
 				}
 			}
 		});
+	},
 
+	get_serial_and_batch_bundle_filters: (doc, cdt, cdn) => {
+		let row = locals[cdt][cdn];
+		return {
+			filters: {
+				'item_code': row.item_code,
+				'voucher_type': doc.doctype,
+				'voucher_no': ['in', [doc.name, '']],
+				'is_cancelled': 0,
+			}
+		}
+	},
+
+	setup_quality_inspection: (frm) => {
+		if (!frm.is_new() && frm.doc.docstatus === 0 && !frm.doc.is_return) {
+			let transaction_controller = new erpnext.TransactionController({ frm: frm });
+			transaction_controller.setup_quality_inspection();
+		}
+	},
+
+	set_route_options_for_new_doc: (frm) => {
 		let batch_no_field = frm.get_docfield('items', 'batch_no');
 		if (batch_no_field) {
 			batch_no_field.get_route_options_for_new_doc = (row) => {
@@ -213,42 +252,6 @@
 			}
 		}
 	},
-
-	get_serial_and_batch_bundle_filters: (doc, cdt, cdn) => {
-		let row = locals[cdt][cdn];
-		return {
-			filters: {
-				'item_code': row.item_code,
-				'voucher_type': doc.doctype,
-				'voucher_no': ['in', [doc.name, '']],
-				'is_cancelled': 0,
-			}
-		}
-	},
-
-	setup_quality_inspection: (frm) => {
-		if (!frm.is_new() && frm.doc.docstatus === 0 && !frm.doc.is_return) {
-			let transaction_controller = new erpnext.TransactionController({ frm: frm });
-			transaction_controller.setup_quality_inspection();
-		}
-	},
-
-	get_scrap_items: (frm) => {
-		frappe.call({
-			doc: frm.doc,
-			method: 'get_scrap_items',
-			args: {
-				recalculate_rate: true
-			},
-			freeze: true,
-			freeze_message: __('Getting Scrap Items'),
-			callback: (r) => {
-				if (!r.exc) {
-					frm.refresh();
-				}
-			}
-		});
-	},
 });
 
 frappe.ui.form.on('Landed Cost Taxes and Charges', {
@@ -303,4 +306,4 @@
 			if (!r.exc) frm.refresh();
 		},
 	});
-}
\ No newline at end of file
+}