unlink reference on cancellation of any invoice
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index af68390..a2ea096 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -110,38 +110,6 @@
 
 	supplier: function() {
 		var me = this;
-		let internal;
-		frappe.db.get_value('Supplier', {name: this.frm.doc.supplier}, 'is_internal_supplier', (r) => {
-			if (r) {
-				internal = r.is_internal_supplier;
-			}
-			if (internal == 1) {
-				frappe.call({
-					method:"erpnext.accounts.doctype.sales_invoice.sales_invoice.get_allowed_companies",
-					args: {supplier: this.frm.doc.supplier},
-					callback: function(r){
-						if (r.message){
-							if (me.frm.doc.company) {
-								me.frm.set_value("company", r.message[0]);
-							}
-							me.frm.set_query('company', function() {
-								return {
-									"filters": {"name": ["in", r.message]}
-									}
-								}
-							);
-						}
-					}
-				});
-			}
-			else {
-				me.frm.set_query('company', function(){
-					return {
-						"filters": {"name": ["like", "%" + "" + "%"]}
-					}
-				});
-			}
-		});
 		if(this.frm.updating_party_details)
 			return;
 		erpnext.utils.get_party_details(this.frm, "erpnext.accounts.party.get_party_details",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 91696c2..8e48cc3 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -663,4 +663,3 @@
 
 	refresh_field('total_billing_amount')
 }
-
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index acd455e..7a8ee24 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1030,7 +1030,7 @@
 		company = frappe.db.get_value("Customer", {"name": doc.get("customer")}, "represents_company")
 	else:
 		party = frappe.db.get_value("Customer", {"is_internal_customer":1, "represents_company": doc.get("company")}, "name")
-		company = frappe.db.get_value("Customer", {"name": doc.get("supplier")}, "represents_company")
+		company = frappe.db.get_value("Supplier", {"name": doc.get("supplier")}, "represents_company")
 
 	return {
 		"party": party, 
@@ -1067,6 +1067,7 @@
 
 		company = details.get("company")
 		default_currency = frappe.db.get_value("Company", company, "default_currency")
+
 		if default_currency != doc.get("currency"):
 			frappe.throw(_("Company currencies of both the companies should match for Inter Company Transactions."))
 
@@ -1106,8 +1107,6 @@
 		target_doc.expense_account = ""
 		target_doc.cost_center = ""
 
-	base_doc = "Sales Invoice"
-	target_doctype = "Purchase Invoice"
 	doclist = get_mapped_doc(doctype, source_name,	{
 		doctype: {
 			"doctype": target_doctype,