Merge pull request #4979 from vjFaLk/leave-improvements

Improved Leave Application / Approver feature
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
index f833ff3..69c88ed 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
@@ -31,16 +31,11 @@
 		{% for(var i=0, l=data.length; i<l; i++) { %}
 			<tr>
 			{% if(__(report.report_name) == "Accounts Receivable" || __(report.report_name) == "Accounts Payable") { %}
-				{% if(data[i][__("Posting Date")]) { %}
+				{% if(data[i][__("Customer")] || data[i][__("Supplier")]) { %}
 					<td>{%= dateutil.str_to_user(data[i][__("Posting Date")]) %}</td>
 					<td>{%= data[i][__("Voucher Type")] %}
 						<br>{%= data[i][__("Voucher No")] %}</td>
 					<td>{%= data[i][__("Customer Name")] || data[i][__("Customer")] || data[i][__("Supplier Name")] || data[i][__("Supplier")] %}
-						{% if(__(report.report_name) == "Accounts Receivable") { %}
-							<br>{%= __("Territory") %}: {%= data[i][__("Territory")] %}
-						{% } else { %}
-							<br>{%= __("Supplier Type") %}: {%= data[i][__("Supplier Type")] %}
-						{% } %}
 						<br>{%= __("Remarks") %}: {%= data[i][__("Remarks")] %}</td>
 					<td style="text-align: right">{%= format_currency(data[i][__("Invoiced Amount")]) %}</td>
 					<td style="text-align: right">{%= format_currency(data[i][__("Paid Amount")]) %}</td>
@@ -48,23 +43,22 @@
 				{% } else { %}
 					<td></td>
 					<td></td>
-					<td><b>{%= data[i][__("Customer")] || data[i][__("Supplier")] || "&nbsp;" %}</b></td>
+					<td><b>{%= __("Total") %}</b></td>
 					<td style="text-align: right">
-						{%= data[i][__("Account")] && format_currency(data[i][__("Invoiced Amount")]) %}</td>
+						{%= format_currency(data[i][__("Invoiced Amount")]) %}</td>
 					<td style="text-align: right">
-						{%= data[i][__("Account")] && format_currency(data[i][__("Paid Amount")]) %}</td>
+						{%= format_currency(data[i][__("Paid Amount")]) %}</td>
 					<td style="text-align: right">
-						{%= data[i][__("Account")] && format_currency(data[i][__("Outstanding Amount")]) %}</td>
+						{%= format_currency(data[i][__("Outstanding Amount")]) %}</td>
 				{% } %}
 			{% } else { %}
 				{% if(data[i][__("Customer")] || data[i][__("Supplier")]|| "&nbsp;") { %}
-					<td>{%= data[i][__("Customer")] || data[i][__("Supplier")] %}
-						{% if(__(report.report_name) == "Accounts Receivable Summary") { %}
-							<br>{%= __("Territory") %}: {%= data[i][__("Territory")] %}
-						{% } else { %}
-							<br>{%= __("Supplier Type") %}: {%= data[i][__("Supplier Type")] %}
-						{% } %}
+					{% if((data[i][__("Customer")] || data[i][__("Supplier")]) != __("'Total'")) { %}
+						<td>{%= data[i][__("Customer")] || data[i][__("Supplier")] %}
 						<br>{%= __("Remarks") %}: {%= data[i][__("Remarks")] %}</td>
+					{% } else { %}
+						<td><b>{%= __("Total") %}</b></td>
+					{% } %}
 					<td style="text-align: right">{%= format_currency(data[i][__("Total Invoiced Amt")]) %}</td>
 					<td style="text-align: right">{%= format_currency(data[i][__("Total Paid Amt")]) %}</td>
 					<td style="text-align: right">{%= format_currency(data[i][__("Total Outstanding Amt")]) %}</td>
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index ea7e660..b79b136 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -135,8 +135,7 @@
 			from `tabSales Order Item` so_item
 			where parent in (%s) and docstatus = 1 and qty > delivered_qty
 			and exists (select * from `tabItem` item where item.name=so_item.item_code
-				and (item.is_pro_applicable = 1
-					or item.is_sub_contracted_item = 1)) %s""" % \
+				and item.is_pro_applicable = 1) %s""" % \
 			(", ".join(["%s"] * len(so_list)), item_condition), tuple(so_list), as_dict=1)
 
 		if self.fg_item:
@@ -150,8 +149,7 @@
 			and pi.parent_item = so_item.item_code
 			and so_item.parent in (%s) and so_item.qty > so_item.delivered_qty
 			and exists (select * from `tabItem` item where item.name=pi.item_code
-				and (item.is_pro_applicable = 1
-					or item.is_sub_contracted_item = 1)) %s""" % \
+				and item.is_pro_applicable = 1) %s""" % \
 			(", ".join(["%s"] * len(so_list)), item_condition), tuple(so_list), as_dict=1)
 
 		self.add_items(items + packed_items)
@@ -171,8 +169,7 @@
 			from `tabMaterial Request Item` mr_item
 			where parent in (%s) and docstatus = 1 and qty > ordered_qty
 			and exists (select * from `tabItem` item where item.name=mr_item.item_code
-				and (item.is_pro_applicable = 1
-					or item.is_sub_contracted_item = 1)) %s""" % \
+				and item.is_pro_applicable = 1) %s""" % \
 			(", ".join(["%s"] * len(mr_list)), item_condition), tuple(mr_list), as_dict=1)
 
 		self.add_items(items)
diff --git a/erpnext/manufacturing/page/bom_browser/bom_browser.js b/erpnext/manufacturing/page/bom_browser/bom_browser.js
index 453d8c5..3c13905 100644
--- a/erpnext/manufacturing/page/bom_browser/bom_browser.js
+++ b/erpnext/manufacturing/page/bom_browser/bom_browser.js
@@ -60,7 +60,6 @@
 					frappe.boot.user.in_create.indexOf("BOM") !== -1;
 		me.can_write = frappe.model.can_write("BOM");
 		me.can_delete = frappe.model.can_delete("BOM");
-
 		this.tree = new frappe.ui.Tree({
 			parent: $(parent),
 			label: me.bom,
@@ -74,15 +73,15 @@
 						return node.expandable;
 					},
 					click: function(node) {
-						frappe.set_route("Form", "BOM", node.data.parent);
+						frappe.set_route("Form", "BOM", node.data.value);
 					}
 				}
 			],
 			get_label: function(node) {
 				if(node.data.qty) {
-					return node.data.qty + " x " + node.data.value;
+					return node.data.qty + " x " + node.data.item_code;
 				} else {
-					return node.data.value;
+					return node.data.item_code || node.data.value;
 				}
 			}
 		});
diff --git a/erpnext/manufacturing/page/bom_browser/bom_browser.py b/erpnext/manufacturing/page/bom_browser/bom_browser.py
index 8051e69..8099389 100644
--- a/erpnext/manufacturing/page/bom_browser/bom_browser.py
+++ b/erpnext/manufacturing/page/bom_browser/bom_browser.py
@@ -6,8 +6,8 @@
 
 @frappe.whitelist()
 def get_children(parent):
-	return frappe.db.sql("""select item_code as value,
-		bom_no as parent, qty,
+	return frappe.db.sql("""select item_code,
+		bom_no as value, qty,
 		if(ifnull(bom_no, "")!="", 1, 0) as expandable
 		from `tabBOM Item`
 		where parent=%s
diff --git a/erpnext/stock/report/item_prices/item_prices.py b/erpnext/stock/report/item_prices/item_prices.py
index ffd128d..ca01d19 100644
--- a/erpnext/stock/report/item_prices/item_prices.py
+++ b/erpnext/stock/report/item_prices/item_prices.py
@@ -20,7 +20,7 @@
 	precision = get_currency_precision() or 2
 	data = []
 	for item in sorted(item_map):
-		data.append([item, item_map[item]["item_name"],
+		data.append([item, item_map[item]["item_name"],item_map[item]["item_group"],
 			item_map[item]["description"], item_map[item]["stock_uom"],
 			flt(last_purchase_rate.get(item, 0), precision),
 			flt(val_rate_map.get(item, 0), precision),
@@ -34,9 +34,9 @@
 def get_columns(filters):
 	"""return columns based on filters"""
 
-	columns = [_("Item") + ":Link/Item:100", _("Item Name") + "::150", _("Description") + "::150", _("UOM") + ":Link/UOM:80",
-		_("Last Purchase Rate") + ":Currency:90", _("Valuation Rate") + ":Currency:80",	_("Sales Price List") + "::80",
-		_("Purchase Price List") + "::80", _("BOM Rate") + ":Currency:90"]
+	columns = [_("Item") + ":Link/Item:100", _("Item Name") + "::150",_("Item Group") + ":Link/Item Group:125", _("Description") + "::150", _("UOM") + ":Link/UOM:80",
+		_("Last Purchase Rate") + ":Currency:90", _("Valuation Rate") + ":Currency:80",	_("Sales Price List") + "::180",
+		_("Purchase Price List") + "::180", _("BOM Rate") + ":Currency:90"]
 
 	return columns
 
@@ -45,9 +45,9 @@
 
 	item_map = {}
 
-	for i in frappe.db.sql("select name, item_name, description, \
+	for i in frappe.db.sql("select name, item_group, item_name, description, \
 		stock_uom from tabItem \
-		order by item_code", as_dict=1):
+		order by item_code, item_group", as_dict=1):
 			item_map.setdefault(i.name, i)
 
 	return item_map
@@ -58,9 +58,9 @@
 	rate = {}
 
 	price_list = frappe.db.sql("""select ip.item_code, ip.buying, ip.selling,
-		concat(ip.price_list, " - ", ip.currency, " ", ip.price_list_rate) as price
-		from `tabItem Price` ip, `tabPrice List` pl
-		where ip.price_list=pl.name and pl.enabled=1""", as_dict=1)
+		concat(ifnull(cu.symbol,ip.currency), " ", round(ip.price_list_rate,2), " - ", ip.price_list) as price
+		from `tabItem Price` ip, `tabPrice List` pl, `tabCurrency` cu
+		where ip.price_list=pl.name and pl.currency=cu.name and pl.enabled=1""", as_dict=1)
 
 	for j in price_list:
 		if j.price:
diff --git a/erpnext/utilities/doctype/address/address.py b/erpnext/utilities/doctype/address/address.py
index f601053..a94bd56 100644
--- a/erpnext/utilities/doctype/address/address.py
+++ b/erpnext/utilities/doctype/address/address.py
@@ -140,17 +140,17 @@
 	return False
 
 def get_address_templates(address):
-	name, template = frappe.db.get_value("Address Template", \
+	result = frappe.db.get_value("Address Template", \
 		{"country": address.get("country")}, ["name", "template"])
 		
-	if not template:
-		name, template = frappe.db.get_value("Address Template", \
+	if not result:
+		result = frappe.db.get_value("Address Template", \
 			{"is_default": 1}, ["name", "template"])
 
-	if not template:
+	if not result:
 		frappe.throw(_("No default Address Template found. Please create a new one from Setup > Printing and Branding > Address Template."))
 	else:
-		return name, template
+		return result
 
 @frappe.whitelist()
 def get_shipping_address(company):