[fix] [minor] rate calculation on server side, only if blank/0 (honour client side calculation sequence), shopping cart settings
diff --git a/accounts/doctype/sales_invoice/test_sales_invoice.py b/accounts/doctype/sales_invoice/test_sales_invoice.py
index 05e4d92..cdd61b9 100644
--- a/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -916,7 +916,6 @@
 			"item_name": "_Test Item Home Desktop 100",
 			"qty": 10,
 			"ref_rate": 62.5,
-			"export_rate": 62.5,
 			"stock_uom": "_Test UOM",
 			"item_tax_rate": json.dumps({"_Test Account Excise Duty - _TC": 10}),
 			"income_account": "Sales - _TC",
@@ -930,7 +929,6 @@
 			"item_name": "_Test Item Home Desktop 200",
 			"qty": 5,
 			"ref_rate": 190.66,
-			"export_rate": 190.66,
 			"stock_uom": "_Test UOM",
 			"income_account": "Sales - _TC",
 			"cost_center": "_Test Cost Center - _TC",
diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py
index 63070a5..938db8c 100644
--- a/controllers/buying_controller.py
+++ b/controllers/buying_controller.py
@@ -98,7 +98,7 @@
 
 			if item.discount_rate == 100.0:
 				item.import_rate = 0.0
-			elif item.import_ref_rate:
+			elif not item.import_rate:
 				item.import_rate = flt(item.import_ref_rate * (1.0 - (item.discount_rate / 100.0)),
 					self.precision("import_rate", item))
 						
diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py
index 033ac83..fb762af 100644
--- a/controllers/selling_controller.py
+++ b/controllers/selling_controller.py
@@ -191,7 +191,7 @@
 			
 			if item.adj_rate == 100:
 				item.export_rate = 0
-			elif item.ref_rate:
+			elif not item.export_rate:
 				item.export_rate = flt(item.ref_rate * (1.0 - (item.adj_rate / 100.0)),
 					self.precision("export_rate", item))
 						
diff --git a/stock/doctype/delivery_note/test_delivery_note.py b/stock/doctype/delivery_note/test_delivery_note.py
index 2e3ab07..c1f09dd 100644
--- a/stock/doctype/delivery_note/test_delivery_note.py
+++ b/stock/doctype/delivery_note/test_delivery_note.py
@@ -33,7 +33,7 @@
 		self.assertEquals(len(si), len(dn.doclist))
 		
 		# modify export_amount
-		si[1].ref_rate = 200
+		si[1].export_rate = 200
 		self.assertRaises(webnotes.ValidationError, webnotes.bean(si).insert)
 		
 	
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index 47e35f1..d2bffcf 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -77,9 +77,9 @@
 		"""
 		customer_defaults = self.get_customer_defaults()
 					
-		customer_defaults["price_list_name"] = customer_defaults.get("price_list") or \
+		customer_defaults["selling_price_list"] = customer_defaults.get("price_list") or \
 			webnotes.conn.get_value("Customer Group", self.doc.customer_group, "default_price_list") or \
-			self.doc.price_list
+			self.doc.selling_price_list
 			
 		for fieldname, val in customer_defaults.items():
 			if self.meta.get_field(fieldname):
diff --git a/website/doctype/shopping_cart_settings/shopping_cart_settings.py b/website/doctype/shopping_cart_settings/shopping_cart_settings.py
index f06c1f7..74cc217 100644
--- a/website/doctype/shopping_cart_settings/shopping_cart_settings.py
+++ b/website/doctype/shopping_cart_settings/shopping_cart_settings.py
@@ -43,7 +43,7 @@
 		
 	def validate_price_lists(self):
 		territory_name_map = self.validate_overlapping_territories("price_lists",
-			"price_list")
+			"selling_price_list")
 		
 		# validate that a Shopping Cart Price List exists for the root territory
 		# as a catch all!
@@ -92,9 +92,9 @@
 				raise_exception=ShoppingCartSetupError)
 		
 		price_list_currency_map = webnotes.conn.get_values("Price List", 
-			[d.price_list for d in self.doclist.get({"parentfield": "price_lists"})],
+			[d.selling_price_list for d in self.doclist.get({"parentfield": "price_lists"})],
 			"currency")
-		
+			
 		expected_to_exist = [currency + "-" + company_currency 
 			for currency in price_list_currency_map.values()
 			if currency != company_currency]
@@ -126,7 +126,7 @@
 		return name
 				
 	def get_price_list(self, billing_territory):
-		price_list = self.get_name_from_territory(billing_territory, "price_lists", "price_list")
+		price_list = self.get_name_from_territory(billing_territory, "price_lists", "selling_price_list")
 		return price_list and price_list[0] or None
 		
 	def get_tax_master(self, billing_territory):
diff --git a/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py b/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py
index cbba566..3417cec 100644
--- a/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py
+++ b/website/doctype/shopping_cart_settings/test_shopping_cart_settings.py
@@ -26,7 +26,7 @@
 			cart_settings.doclist.append({
 				"doctype": "Shopping Cart Price List",
 				"parentfield": "price_lists",
-				"price_list": price_list
+				"selling_price_list": price_list
 			})
 		
 		for price_list in ("_Test Price List Rest of the World", "_Test Price List India",
@@ -34,13 +34,13 @@
 			_add_price_list(price_list)
 		
 		controller = cart_settings.make_controller()
-		controller.validate_overlapping_territories("price_lists", "price_list")
+		controller.validate_overlapping_territories("price_lists", "selling_price_list")
 		
 		_add_price_list("_Test Price List 2")
 		
 		controller = cart_settings.make_controller()
 		self.assertRaises(ShoppingCartSetupError, controller.validate_overlapping_territories,
-			"price_lists", "price_list")
+			"price_lists", "selling_price_list")
 			
 		return cart_settings