[fix] address queries + tests
diff --git a/erpnext/utilities/address_and_contact.py b/erpnext/utilities/address_and_contact.py
index eaa71f9..f3435ae 100644
--- a/erpnext/utilities/address_and_contact.py
+++ b/erpnext/utilities/address_and_contact.py
@@ -122,7 +122,7 @@
 def delete_contact_and_address(doctype, name):
 	for parenttype in ('Contact', 'Address'):
 		items = frappe.db.sql("""select parent from `tabDynamic Link`
-			where parenttype=%s and link_type=%s and link_name=%s""",
+			where parenttype=%s and link_doctype=%s and link_name=%s""",
 			(parenttype, doctype, name))
 
 		for name in items: