[Fix] Delivery Note fixed
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index ca66ee2..ee25272 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -8,8 +8,7 @@
 erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
 	onload: function() {
 		this._super();
-		console.log('----> TESTING');
-		this.setup_quality_inspection("Incoming");
+		
 		if(!this.frm.doc.__islocal) {
 			// show credit_to in print format
 			if(!this.frm.doc.supplier && this.frm.doc.credit_to) {
@@ -34,6 +33,10 @@
 			this.show_stock_ledger();
 		}
 
+		if (doc.update_stock==1){
+			this.setup_quality_inspection("Incoming");
+		}
+
 		if(!doc.is_return && doc.docstatus==1) {
 			if(doc.outstanding_amount != 0) {
 				this.frm.add_custom_button(__('Payment'), this.make_payment_entry, __("Make"));
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 2e07e4f..53a489c 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -146,14 +146,13 @@
 			return {
 				"inspection_type": inspection_type,
 				"reference_type": me.frm.doc.doctype,
-				"purchase_receipt": me.frm.doc.name,
+				"reference_name": me.frm.doc.name,
 				"item_code": doc.item_code,
 				"description": doc.description,
 				"item_serial_no": doc.serial_no ? doc.serial_no.split("\n")[0] : null,
 				"batch_no": doc.batch_no
 			}
 		}
-		console.log(quality_inspection_field);
 		this.frm.set_query("quality_inspection", "items", function(doc, cdt, cdn) {
 			var d = locals[cdt][cdn];
 			return {
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 2597280..baeb069 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -8,19 +8,6 @@
 
 frappe.ui.form.on("Delivery Note", {
 	setup: function(frm) {
-		var quality_inspection = frappe.meta.get_docfield("Delivery Note Item", "quality_inspection");
-		quality_inspection.get_route_options_for_new_doc = function(field) {
-			if(frm.is_new()) return;
-			var doc = field.doc;
-			return {
-				"inspection_type": "Outgoing",
-				"delivery_note_no": frm.doc.name,
-				"item_code": doc.item_code,
-				"description": doc.description,
-				"item_serial_no": doc.serial_no ? doc.serial_no.split("\n")[0] : null,
-				"batch_no": doc.batch_no
-			}
-		}
 
 		frm.set_indicator_formatter('item_code',
 			function(doc) {
@@ -36,20 +23,15 @@
 			}
 		})
 
-		frm.set_query("quality_inspection", "items", function(doc, cdt, cdn) {
-			var d = locals[cdt][cdn];
-			return {
-				filters: {
-					docstatus: 1,
-					inspection_type: "Outgoing",
-					item_code: d.item_code
-				}
-			}
-		})
 	}
 });
 
 erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({
+	onload: function() {
+		this._super();
+		this.setup_quality_inspection("Outgoing");
+	},
+
 	refresh: function(doc, dt, dn) {
 		this._super();
 		if (!doc.is_return && doc.status!="Closed") {