[fix] Hide Make Delivery Note button, if Sales Invoice is made from Delivery Note. Hide Make Invoice Button, if Delivery Note is made from Sales Invoice
diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js
index 1378fab..f224c35 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -62,8 +62,18 @@
 
 			cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
 
-			if(cint(doc.update_stock)!=1)
-				cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
+			if(cint(doc.update_stock)!=1) {
+				// show Make Delivery Note button only if Sales Invoice is not created from Delivery Note
+				var from_delivery_note = false;
+				from_delivery_note = cur_frm.get_doclist({parentfield: "entries"})
+					.some(function(item) { 
+						return item.delivery_note ? true : false; 
+					});
+				
+				if(!from_delivery_note)
+					cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
+			}
+				
 
 			if(doc.outstanding_amount!=0)
 				cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js
index 063b258..80c2646 100644
--- a/stock/doctype/delivery_note/delivery_note.js
+++ b/stock/doctype/delivery_note/delivery_note.js
@@ -16,7 +16,17 @@
 	refresh: function(doc, dt, dn) {
 		this._super();
 		
-		if(!doc.__billing_complete && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice);
+		if(!doc.__billing_complete && doc.docstatus==1) {
+			// show Make Invoice button only if Delivery Note is not created from Sales Invoice
+			var from_sales_invoice = false;
+			from_sales_invoice = cur_frm.get_doclist({parentfield: "delivery_note_details"})
+				.some(function(item) { 
+					return item.prevdoc_doctype==="Sales Invoice" ? true : false; 
+				});
+			
+			if(!from_sales_invoice)
+				cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice);
+		}
 	
 		if(flt(doc.per_installed, 2) < 100 && doc.docstatus==1) 
 			cur_frm.add_custom_button('Make Installation Note', this.make_installation_note);