Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js
index e15e076..04263c3 100644
--- a/buying/doctype/purchase_common/purchase_common.js
+++ b/buying/doctype/purchase_common/purchase_common.js
@@ -111,11 +111,6 @@
 					address: this.frm.doc.supplier_address, 
 					contact: this.frm.doc.contact_person
 				},
-				callback: function(r) {
-					if(!r.exc) {
-						me.frm.refresh_fields();
-					}
-				}
 			});
 		}
 	},
diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js
index e9f185b..9a13c4f 100644
--- a/selling/doctype/sales_common/sales_common.js
+++ b/selling/doctype/sales_common/sales_common.js
@@ -165,9 +165,6 @@
 				},
 				method: "set_customer_address",
 				freeze: true,
-				callback: function(r) {
-					me.frm.refresh_fields();
-				}
 			});
 		}
 	},
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index de229b9..8894cb4 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -135,10 +135,7 @@
 		
 	def set_lead_defaults(self):
 		self.doc.fields.update(self.get_lead_defaults())
-			
 	
-	# Get Customer Address
-	# -----------------------
 	def get_customer_address(self, args):
 		args = load_json(args)		
 		ret = {
@@ -396,14 +393,10 @@
 		"contact_mobile", "contact_phone", "contact_designation", "contact_department"]:
 			out[fieldname] = None
 			
-	condition = ""
-	if contact_name:
-		condition = " name = '%s'" % contact_name
-	elif party_field and party_name:
-		condition = " `%s`='%s'" % (party_field, party_name)
-		
-	contact = webnotes.conn.sql("""select * from `tabContact` where %s
-		order by is_primary_contact desc, name asc limit 1""" % condition, as_dict=True)
+	if not contact_name and party_field:
+		contact_name = get_default_contact(party_field, party_name)
+	
+	contact = webnotes.conn.sql("""select * from `tabContact` where name=%s""", contact_name, as_dict=True)
 
 	if contact:
 		contact = contact[0]
@@ -417,7 +410,7 @@
 			"contact_designation": contact.get("designation"),
 			"contact_department": contact.get("department")
 		})
-		
+
 	return out
 	
 def get_address_territory(address_doc):