[fix] setup wont be called if declared inside setup
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 2ba2aba..457b6aa 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -5,7 +5,6 @@
 
 frappe.ui.form.on("Sales Order", {
 	setup: function(frm) {
-		$.extend(frm.cscript, new erpnext.selling.SalesOrderController({frm: frm}));
 		frm.custom_make_buttons = {
 			'Delivery Note': 'Delivery',
 			'Sales Invoice': 'Invoice',
@@ -347,3 +346,5 @@
 		}
 	}
 });
+
+$.extend(cur_frm.cscript, new erpnext.selling.SalesOrderController({frm: cur_frm}));
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index c441df2..46d536d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -63,7 +63,6 @@
 		});
 
 
-		$.extend(frm.cscript, new erpnext.stock.DeliveryNoteController({frm: frm}));
 	},
 	print_without_amount: function(frm) {
 		erpnext.stock.delivery_note.set_print_hide(frm.doc);
@@ -86,7 +85,6 @@
 	}
 });
 
-
 erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({
 	setup: function(doc) {
 		this.setup_posting_date_time_check();
@@ -225,6 +223,8 @@
 
 });
 
+$.extend(cur_frm.cscript, new erpnext.stock.DeliveryNoteController({frm: cur_frm}));
+
 frappe.ui.form.on('Delivery Note', {
 	setup: function(frm) {
 		if(frm.doc.company) {
@@ -268,3 +268,4 @@
 			dn_fields['taxes'].print_hide = 0;
 	}
 }
+
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 1214346..5315253 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -4,7 +4,6 @@
 
 frappe.ui.form.on('Stock Entry', {
 	setup: function(frm) {
-		$.extend(frm.cscript, new erpnext.stock.StockEntry({frm: frm}));
 
 		frm.set_query('production_order', function() {
 			return {
@@ -583,3 +582,5 @@
 	});
 
 }
+
+$.extend(cur_frm.cscript, new erpnext.stock.StockEntry({frm: cur_frm}));