more updates to party
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index dda6219..df9ef94 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -75,6 +75,19 @@
 
 		this.is_opening(doc);
 	},
+
+	supplier: function() {
+		if(this.frm.updating_party_details)
+			return;
+		erpnext.selling.get_party_details(this.frm, 
+			"erpnext.accounts.party.get_party_details", {
+				posting_date: this.frm.doc.posting_date,
+				company: this.frm.doc.company,
+				party: this.frm.doc.supplier,
+				party_type: "Supplier",
+				account: this.frm.doc.debit_to
+			})
+	},
 	
 	credit_to: function() {
 		this.supplier();
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index db42a12..a9950ca 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -12,8 +12,9 @@
 
 import webnotes.defaults
 
-	
 from erpnext.controllers.buying_controller import BuyingController
+from erpnext.accounts.party import get_party_account, get_due_date
+
 class DocType(BuyingController):
 	def __init__(self,d,dl):
 		self.doc, self.doclist = d, dl 
@@ -59,31 +60,16 @@
 		self.update_valuation_rate("entries")
 		self.validate_multiple_billing("Purchase Receipt", "pr_detail", "import_amount", 
 			"purchase_receipt_details")
-
-	def get_credit_to(self):
-		ret = {}
-		if self.doc.supplier:
-			acc_head = webnotes.conn.sql("""select name, credit_days from `tabAccount` 
-				where (name = %s or (master_name = %s and master_type = 'supplier')) 
-				and docstatus != 2 and company = %s""", 
-				(cstr(self.doc.supplier) + " - " + self.company_abbr, 
-				self.doc.supplier, self.doc.company))
+	
+	def set_missing_values(self, for_validate=False):
+		if not self.doc.credit_to:
+			self.doc.credit_to = get_party_account(self.doc.company, self.doc.supplier, "Supplier")
+		if not self.doc.due_date:
+			self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.supplier, "Supplier",
+				self.doc.credit_to, self.doc.company)
 		
-			if acc_head and acc_head[0][0]:
-				ret['credit_to'] = acc_head[0][0]
-				if not self.doc.due_date:
-					ret['due_date'] = add_days(cstr(self.doc.posting_date), 
-						acc_head and cint(acc_head[0][1]) or 0)
-			elif not acc_head:
-				msgprint("%s does not have an Account Head in %s. \
-					You must first create it from the Supplier Master" % \
-					(self.doc.supplier, self.doc.company))
-		return ret
-		
-	def set_supplier_defaults(self):
-		self.doc.fields.update(self.get_credit_to())
-		super(DocType, self).set_supplier_defaults()
-		
+		super(DocType, self).set_missing_values(for_validate)
+	
 	def get_advances(self):
 		super(DocType, self).get_advances(self.doc.credit_to, 
 			"Purchase Invoice Advance", "advance_allocation_details", "debit")
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 33a01fe..fdf2265 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -159,12 +159,12 @@
 		if(this.frm.updating_party_details)
 			return;
 		erpnext.selling.get_party_details(this.frm, 
-			"erpnext.accounts.doctype.sales_invoice.sales_invoice.get_party_details",
-			{
+			"erpnext.accounts.party.get_party_details", {
 				posting_date: this.frm.doc.posting_date,
 				company: this.frm.doc.company,
-				customer: this.frm.doc.customer,
-				debit_to: this.frm.doc.debit_to
+				party: this.frm.doc.customer,
+				party_type: "Customer",
+				account: this.frm.doc.debit_to
 			})
 	},
 	
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 4b427bb..5814e56 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -153,7 +153,7 @@
 		if not self.doc.debit_to:
 			self.doc.debit_to = get_party_account(self.doc.company, self.doc.customer, "Customer")
 		if not self.doc.due_date:
-			self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.customer, 
+			self.doc.due_date = get_due_date(self.doc.posting_date, self.doc.customer, "Customer",
 				self.doc.debit_to, self.doc.company)
 		
 		super(DocType, self).set_missing_values(for_validate)
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index db37c4f..0eedd99 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -7,7 +7,7 @@
 from webnotes import _
 
 @webnotes.whitelist()
-def get_party_details(party=None, account=None, party_type="Customer"):
+def get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None):
 	if not webnotes.has_permission(party_type, "read", party):
 		webnotes.throw("No Permission")
 	
@@ -49,7 +49,7 @@
 	due_date = None
 	if posting_date:
 		credit_days = 0
-		if debit_to:
+		if account:
 			credit_days = webnotes.conn.get_value("Account", account, "credit_days")
 		if party and not credit_days:
 			credit_days = webnotes.conn.get_value(party_type, party, "credit_days")
@@ -66,7 +66,7 @@
 		
 	company_details = webnotes.conn.get_value("Company", company, 
 		["abbr", "receivables_group", "payables_group"], as_dict=True)
-	if not webnotes.conn.exists("Account", (party + " - " + abbr)):
+	if not webnotes.conn.exists("Account", (party + " - " + company_details.abbr)):
 		parent_account = company_details.receivables_group \
 			if party_type=="Customer" else company_details.payables_group
 
@@ -82,4 +82,4 @@
 			"freeze_account": "No"
 		}).insert(ignore_permissions=True)
 		
-		msgprint(_("Account Created") + ": " + account.doc.name)
+		webnotes.msgprint(_("Account Created") + ": " + account.doc.name)
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index 1f61deb..0c2a601 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -129,7 +129,7 @@
 	return out
 	
 @webnotes.whitelist()
-def get_supplier_details(supplier):
+def get_supplier_details(supplier, price_list=None, currency=None):
 	if not webnotes.has_permission("Supplier", "read", supplier):
 		webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)
 
@@ -143,7 +143,7 @@
 	})
 	
 	out.supplier_name = supplier.supplier_name
-	out.currency = supplier.default_currency
-	out.buying_price_list = supplier.default_price_list
+	out.currency = supplier.default_currency or currency
+	out.buying_price_list = supplier.default_price_list or price_list
 		
 	return out
\ No newline at end of file
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index ee786cf..a20eecc 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -33,7 +33,7 @@
 		
 		# set contact and address details for supplier, if they are not mentioned
 		if self.doc.supplier:
-			self.doc.update_if_not_set(get_supplier_details(self.doc.supplier))
+			self.doc.update_if_missing(get_supplier_details(self.doc.supplier))
 
 		self.set_missing_item_details(get_item_details)
 		if self.doc.fields.get("__islocal"):
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 73b341d..b0eafe0 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -35,10 +35,10 @@
 	def set_missing_lead_customer_details(self):
 		from erpnext.selling.doctype.customer.customer import get_customer_details
 		if self.doc.customer:
-			self.doc.update_if_not_set(get_customer_details(self.doc.customer))
+			self.doc.update_if_missing(get_customer_details(self.doc.customer))
 		
 		elif self.doc.lead:
-			self.doc.update_if_not_set(self.get_lead_defaults())
+			self.doc.update_if_missing(self.get_lead_defaults())
 						
 	def set_price_list_and_item_details(self):
 		self.set_price_list_currency("Selling")
diff --git a/erpnext/public/build.json b/erpnext/public/build.json
index bb81a58..d089178 100644
--- a/erpnext/public/build.json
+++ b/erpnext/public/build.json
@@ -12,6 +12,6 @@
 		"public/js/feature_setup.js",
 		"public/js/utils.js",
 		"public/js/queries.js",
-		"public/js/utils/customer_supplier.js"
+		"public/js/utils/party.js"
 	]
 }
\ No newline at end of file
diff --git a/erpnext/public/js/utils/customer_supplier.js b/erpnext/public/js/utils/party.js
similarity index 82%
rename from erpnext/public/js/utils/customer_supplier.js
rename to erpnext/public/js/utils/party.js
index a856377..c068ff2 100644
--- a/erpnext/public/js/utils/customer_supplier.js
+++ b/erpnext/public/js/utils/party.js
@@ -6,16 +6,25 @@
 	if(!method) {
 		if(frm.doc.customer) {
 			method = "erpnext.selling.doctype.customer.customer.get_customer_details";
+			var price_list_field = "selling_price_list";
 		} else {
 			method = "erpnext.buying.doctype.supplier.supplier.get_supplier_details";
+			var price_list_field = "buying_price_list";
 		}
 	}
 	if(!args) {
 		if(frm.doc.customer) {
-			args = { customer: frm.doc.customer };
+			args = { 
+				customer: frm.doc.customer,
+				price_list: frm.doc.selling_price_list
+			};
 		} else {
-			args = { supplier: frm.doc.supplier };
+			args = { 
+				supplier: frm.doc.supplier,
+				price_list: frm.doc.buying_price_list
+			};
 		}
+		args.currency = frm.doc.currency;
 	}
 	wn.call({
 		method: method,
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index fda93da..aa28a19 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -165,7 +165,7 @@
 	return out
 
 @webnotes.whitelist()
-def get_customer_details(customer):
+def get_customer_details(customer, price_list=None, currency=None):
 	if not webnotes.has_permission("Customer", "read", customer):
 		webnotes.throw("Not Permitted", webnotes.PermissionError)
 		
@@ -196,17 +196,20 @@
 			out[f] = customer.get("default_" + f)
 
 	# price list
-	from webnotes.defaults import get_defaults_for
-	user_default_price_list = get_defaults_for(webnotes.session.user).get("selling_price_list")
-	user_default_price_list = cstr(user_default_price_list) \
-		if not isinstance(user_default_price_list, list) else ""
+	out.selling_price_list = webnotes.conn.get_defaults("selling_price_list", webnotes.session.user)
+	if isinstance(out.selling_price_list, list):
+		out.selling_price_list = None
 	
-	out.selling_price_list = user_default_price_list or customer.price_list or webnotes.conn.get_value("Customer Group",
-		customer.customer_group, "default_price_list")
+	out.selling_price_list = out.selling_price_list or customer.price_list \
+		or webnotes.conn.get_value("Customer Group", customer.customer_group, "default_price_list")
+		or price_list
 	
 	if out.selling_price_list:
 		out.price_list_currency = webnotes.conn.get_value("Price List", out.selling_price_list, "currency")
 	
+	if not out.currency:
+		out.currency = currency
+	
 	# sales team
 	out.sales_team = [{
 		"sales_person": d.sales_person,