Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.txt b/accounts/doctype/purchase_invoice/purchase_invoice.txt
index 64b9f5c..44cd20f 100755
--- a/accounts/doctype/purchase_invoice/purchase_invoice.txt
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:51:06", 
+  "modified": "2013-07-23 15:27:03", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -273,7 +273,7 @@
   "label": "Price List Currency", 
   "options": "Currency", 
   "print_hide": 1, 
-  "read_only": 0
+  "read_only": 1
  }, 
  {
   "depends_on": "price_list_name", 
diff --git a/accounts/doctype/sales_invoice/sales_invoice.txt b/accounts/doctype/sales_invoice/sales_invoice.txt
index e3c60a0..a04fca4 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.txt
+++ b/accounts/doctype/sales_invoice/sales_invoice.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:05", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:48:05", 
+  "modified": "2013-07-23 15:28:32", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -279,7 +279,7 @@
   "label": "Price List Currency", 
   "options": "Currency", 
   "print_hide": 1, 
-  "read_only": 0, 
+  "read_only": 1, 
   "reqd": 1
  }, 
  {
diff --git a/buying/doctype/purchase_order/purchase_order.txt b/buying/doctype/purchase_order/purchase_order.txt
index bb310aa..a79d98e 100644
--- a/buying/doctype/purchase_order/purchase_order.txt
+++ b/buying/doctype/purchase_order/purchase_order.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-07-19 22:04:17", 
+  "modified": "2013-07-23 15:26:28", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -225,7 +225,8 @@
   "fieldtype": "Link", 
   "label": "Price List Currency", 
   "options": "Currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 1
  }, 
  {
   "depends_on": "price_list_name", 
diff --git a/buying/doctype/supplier_quotation/supplier_quotation.txt b/buying/doctype/supplier_quotation/supplier_quotation.txt
index 3cb5046..e18e011 100644
--- a/buying/doctype/supplier_quotation/supplier_quotation.txt
+++ b/buying/doctype/supplier_quotation/supplier_quotation.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:45", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:49:31", 
+  "modified": "2013-07-23 15:27:23", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -222,7 +222,8 @@
   "fieldtype": "Link", 
   "label": "Price List Currency", 
   "options": "Currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 1
  }, 
  {
   "depends_on": "price_list_name", 
diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py
index 7bcc92e..acb6077 100644
--- a/controllers/accounts_controller.py
+++ b/controllers/accounts_controller.py
@@ -57,10 +57,7 @@
 		# TODO - change this, since price list now has only one currency allowed
 		if self.meta.get_field("price_list_name") and self.doc.price_list_name and \
 			not self.doc.price_list_currency:
-				self.doc.fields.update(get_price_list_currency({
-					"price_list_name": self.doc.price_list_name, 
-					"buying_or_selling": buying_or_selling
-				}))
+				self.doc.fields.update(get_price_list_currency(self.doc.price_list_name))
 				
 				if self.doc.price_list_currency:
 					if not self.doc.plc_conversion_rate:
diff --git a/public/js/transaction.js b/public/js/transaction.js
index 421a7a5..8770ba9 100644
--- a/public/js/transaction.js
+++ b/public/js/transaction.js
@@ -74,14 +74,9 @@
 	
 	company: function() {
 		if(this.frm.doc.company && this.frm.fields_dict.currency) {
-			var me = this;
 			var company_currency = this.get_company_currency();
-			$.each(["currency", "price_list_currency"], function(i, fieldname) {
-				if(!me.frm.doc[fieldname]) {
-					me.frm.set_value(fieldname, company_currency);
-					me.script_manager.trigger(fieldname);
-				}
-			});
+			this.frm.set_value("currency", company_currency);
+			this.frm.script_manager.trigger("currency");
 		}
 	},
 	
@@ -123,10 +118,9 @@
 		if(this.frm.doc.price_list_name) {
 			this.frm.call({
 				method: "setup.utils.get_price_list_currency",
-				args: { args: {
+				args: { 
 					price_list_name: this.frm.doc.price_list_name,
-					buying_or_selling: buying_or_selling
-				}},
+				},
 				callback: function(r) {
 					if(!r.exc) {
 						me.price_list_currency();
diff --git a/public/js/utils.js b/public/js/utils.js
index 743c02b..96b312f 100644
--- a/public/js/utils.js
+++ b/public/js/utils.js
@@ -20,7 +20,7 @@
 		if(!company && cur_frm)
 			company = cur_frm.doc.company;
 		if(company)
-			return wn.model.get(":Company", company).default_currency || wn.boot.sysdefaults.currency;
+			return wn.model.get_doc(":Company", company).default_currency || wn.boot.sysdefaults.currency;
 		else
 			return wn.boot.sysdefaults.currency;
 	},
diff --git a/selling/doctype/quotation/quotation.txt b/selling/doctype/quotation/quotation.txt
index 19eefa3..7f16466 100644
--- a/selling/doctype/quotation/quotation.txt
+++ b/selling/doctype/quotation/quotation.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:08", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:48:56", 
+  "modified": "2013-07-23 15:27:53", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -301,7 +301,7 @@
   "label": "Price List Currency", 
   "options": "Currency", 
   "print_hide": 1, 
-  "read_only": 0, 
+  "read_only": 1, 
   "reqd": 1
  }, 
  {
diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js
index 45a9b5b..e3e5f87 100644
--- a/selling/doctype/sales_common/sales_common.js
+++ b/selling/doctype/sales_common/sales_common.js
@@ -112,6 +112,14 @@
 				}
 			});
 		}
+		
+		if(this.frm.fields_dict.sales_team && this.frm.fields_dict.sales_team.grid.get_field("sales_person")) {
+			this.frm.set_query("sales_person", "sales_team", function() {
+				return {
+					filters: { is_group: "No" }
+				};
+			});
+		}
 	},
 	
 	refresh: function(doc) {
@@ -189,6 +197,7 @@
 							barcode: item.barcode,
 							warehouse: item.warehouse,
 							doctype: me.frm.doc.doctype,
+							parentfield: item.parentfield,
 							customer: me.frm.doc.customer,
 							currency: me.frm.doc.currency,
 							conversion_rate: me.frm.doc.conversion_rate,
@@ -287,13 +296,13 @@
 	
 	warehouse: function(doc, cdt, cdn) {
 		var item = wn.model.get_doc(cdt, cdn);
-		if(item.item_code && (item.warehouse || item.reserved_warehouse)) {
+		if(item.item_code && item.warehouse) {
 			this.frm.call({
 				method: "selling.utils.get_available_qty",
 				child: item,
 				args: {
 					item_code: item.item_code,
-					warehouse: item.warehouse || item.reserved_warehouse,
+					warehouse: item.warehouse,
 				},
 			});
 		}
diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js
index 4368d5b..7eeb22d 100644
--- a/selling/doctype/sales_order/sales_order.js
+++ b/selling/doctype/sales_order/sales_order.js
@@ -97,11 +97,21 @@
 	tc_name: function() {
 		this.get_terms();
 	},
-
-	reserved_warehouse: function(doc, cdt, cdn) {
-		this.warehouse(doc, cdt, cdn);
-	},
 	
+	reserved_warehouse: function(doc, cdt, cdn) {
+		var item = wn.model.get_doc(cdt, cdn);
+		if(item.item_code && item.reserved_warehouse) {
+			this.frm.call({
+				method: "selling.utils.get_available_qty",
+				child: item,
+				args: {
+					item_code: item.item_code,
+					warehouse: item.reserved_warehouse,
+				},
+			});
+		}
+	},
+
 	make_material_request: function() {
 		wn.model.open_mapped_doc({
 			method: "selling.doctype.sales_order.sales_order.make_material_request",
diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py
index b67510d..210e56f 100644
--- a/selling/doctype/sales_order/sales_order.py
+++ b/selling/doctype/sales_order/sales_order.py
@@ -366,7 +366,7 @@
 		}
 	}, target_doclist, postprocess)
 	
-	return [d.fields for d in doclist]
+	return [(d if isinstance(d, dict) else d.fields) for d in doclist]
 
 @webnotes.whitelist()
 def make_delivery_note(source_name, target_doclist=None):	
diff --git a/selling/doctype/sales_order/sales_order.txt b/selling/doctype/sales_order/sales_order.txt
index 37c9e21..3e6cbe4 100644
--- a/selling/doctype/sales_order/sales_order.txt
+++ b/selling/doctype/sales_order/sales_order.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-06-18 12:39:59", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:47:46", 
+  "modified": "2013-07-23 15:27:39", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -311,6 +311,7 @@
   "label": "Price List Currency", 
   "options": "Currency", 
   "print_hide": 1, 
+  "read_only": 1, 
   "reqd": 1
  }, 
  {
diff --git a/selling/utils.py b/selling/utils.py
index cbfaee7..bf4f081 100644
--- a/selling/utils.py
+++ b/selling/utils.py
@@ -58,9 +58,15 @@
 	
 	_validate_item_details(args, item_bean.doc)
 	
-	out = _get_basic_details(args, item_bean)
-	
 	meta = webnotes.get_doctype(args.doctype)
+
+	# hack! for Sales Order Item
+	warehouse_fieldname = "warehouse"
+	if meta.get_field("reserved_warehouse", parentfield=args.parentfield):
+		warehouse_fieldname = "reserved_warehouse"
+	
+	out = _get_basic_details(args, item_bean, warehouse_fieldname)
+	
 	if meta.get_field("currency"):
 		out.base_ref_rate = out.basic_rate = out.ref_rate = out.export_rate = 0.0
 		
@@ -69,8 +75,8 @@
 			
 	out.update(_get_item_discount(out.item_group, args.customer))
 	
-	if out.warehouse or out.reserved_warehouse:
-		out.update(get_available_qty(args.item_code, out.warehouse or out.reserved_warehouse))
+	if out.get(warehouse_fieldname):
+		out.update(get_available_qty(args.item_code, out.get(warehouse_fieldname)))
 	
 	out.customer_item_code = _get_customer_item_code(args, item_bean)
 	
@@ -108,13 +114,13 @@
 		msgprint(_("Item") + (" %s: " % item.name) + _("not a sales item"),
 			raise_exception=True)
 			
-def _get_basic_details(args, item_bean):
+def _get_basic_details(args, item_bean, warehouse_fieldname):
 	item = item_bean.doc
+	
 	out = webnotes._dict({
 			"item_code": item.name,
 			"description": item.description_html or item.description,
-			"reserved_warehouse": item.default_warehouse or args.warehouse or args.reserved_warehouse,
-			"warehouse": item.default_warehouse or args.warehouse,
+			warehouse_fieldname: item.default_warehouse or args.get(warehouse_fieldname),
 			"income_account": item.default_income_account or args.income_account \
 				or webnotes.conn.get_value("Company", args.company, "default_income_account"),
 			"expense_account": item.purchase_account or args.expense_account \
diff --git a/setup/utils.py b/setup/utils.py
index e1463fa..adfa4f7 100644
--- a/setup/utils.py
+++ b/setup/utils.py
@@ -44,20 +44,6 @@
 	return result or []
 
 @webnotes.whitelist()
-def get_price_list_currency(args):
-	"""
-		args = {
-			"price_list_name": "Something",
-			"buying_or_selling": "Buying" or "Selling"
-		}
-	"""
-	if isinstance(args, basestring):
-		args = json.loads(args)
-	
-	result = webnotes.conn.sql("""select distinct ref_currency from `tabItem Price`
-		where price_list_name=%s and buying_or_selling=%s""",
-		(args.get("price_list_name"), args.get("buying_or_selling")))
-	if result and len(result)==1:
-		return {"price_list_currency": result[0][0]}
-	else:
-		return {}
\ No newline at end of file
+def get_price_list_currency(price_list_name):
+	return {"price_list_currency": webnotes.conn.get_value("Price List", price_list_name, 
+		"currency")}
\ No newline at end of file
diff --git a/stock/doctype/delivery_note/delivery_note.txt b/stock/doctype/delivery_note/delivery_note.txt
index cfdd8cd..aa9530f 100644
--- a/stock/doctype/delivery_note/delivery_note.txt
+++ b/stock/doctype/delivery_note/delivery_note.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:09", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:48:27", 
+  "modified": "2013-07-23 15:28:18", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -303,7 +303,7 @@
   "label": "Price List Currency", 
   "options": "Currency", 
   "print_hide": 1, 
-  "read_only": 0, 
+  "read_only": 1, 
   "reqd": 1
  }, 
  {
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.txt b/stock/doctype/purchase_receipt/purchase_receipt.txt
index 94136ae..f5b64d2 100755
--- a/stock/doctype/purchase_receipt/purchase_receipt.txt
+++ b/stock/doctype/purchase_receipt/purchase_receipt.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-07-09 12:50:25", 
+  "modified": "2013-07-23 15:26:50", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -251,7 +251,8 @@
   "hidden": 0, 
   "label": "Price List Currency", 
   "options": "Currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 1
  }, 
  {
   "depends_on": "price_list_name",