Merge branch 'develop'
diff --git a/erpnext/__version__.py b/erpnext/__version__.py
index 67cff5d..9049b13 100644
--- a/erpnext/__version__.py
+++ b/erpnext/__version__.py
@@ -1,2 +1,2 @@
 from __future__ import unicode_literals
-__version__ = '5.2.0'
+__version__ = '5.2.1'
diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json
index 8146c63..e60d9ab 100644
--- a/erpnext/accounts/doctype/account/account.json
+++ b/erpnext/accounts/doctype/account/account.json
@@ -173,7 +173,7 @@
  "icon": "icon-money", 
  "idx": 1, 
  "in_create": 0, 
- "modified": "2015-06-14 20:57:55.471334", 
+ "modified": "2015-07-20 03:54:14.297995", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Account", 
@@ -257,5 +257,5 @@
    "write": 1
   }
  ], 
- "search_fields": "is_group"
+ "search_fields": ""
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 3ea92e1..1ecde64 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -109,7 +109,7 @@
 
 	against_jv: function(doc, cdt, cdn) {
 		var d = frappe.get_doc(cdt, cdn);
-		if (d.against_jv && d.party && !flt(d.credit) && !flt(d.debit)) {
+		if (d.against_jv && !flt(d.credit) && !flt(d.debit)) {
 			this.get_outstanding('Journal Entry', d.against_jv, d);
 		}
 	},
@@ -119,7 +119,8 @@
 		var args = {
 			"doctype": doctype,
 			"docname": docname,
-			"party": child.party
+			"party": child.party,
+			"account": child.account
 		}
 
 		return this.frm.call({
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 23d4c73..dc620ed 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -545,12 +545,14 @@
 @frappe.whitelist()
 def get_outstanding(args):
 	args = eval(args)
-	if args.get("doctype") == "Journal Entry" and args.get("party"):
+	if args.get("doctype") == "Journal Entry":
+		condition = " and party=%(party)s" if args.get("party") else ""
+			
 		against_jv_amount = frappe.db.sql("""
 			select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
-			from `tabJournal Entry Account` where parent=%s and party=%s
+			from `tabJournal Entry Account` where parent=%(docname)s and account=%(account)s {0}
 			and ifnull(against_invoice, '')='' and ifnull(against_voucher, '')=''
-			and ifnull(against_jv, '')=''""", (args['docname'], args['party']))
+			and ifnull(against_jv, '')=''""".format(condition), args)
 
 		against_jv_amount = flt(against_jv_amount[0][0]) if against_jv_amount else 0
 		if against_jv_amount > 0:
diff --git a/erpnext/config/desktop.py b/erpnext/config/desktop.py
index b0c7345..498d100 100644
--- a/erpnext/config/desktop.py
+++ b/erpnext/config/desktop.py
@@ -64,7 +64,7 @@
 			"type": "module"
 		},
 		"Learn": {
-			"color": "#7272FF",
+			"color": "#FCB868",
 			"force_show": True,
 			"icon": "icon-facetime-video",
 			"type": "module",
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 3418b9f..a87c8f0 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -5,7 +5,7 @@
 app_description = "Open Source Enterprise Resource Planning for Small and Midsized Organizations"
 app_icon = "icon-th"
 app_color = "#e74c3c"
-app_version = "5.2.0"
+app_version = "5.2.1"
 
 error_report_email = "support@erpnext.com"
 
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index b556172..a56929d 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -19,10 +19,13 @@
 				jv.company = cur_frm.doc.company;
 				jv.remark = 'Payment against Expense Claim: ' + cur_frm.doc.name;
 				jv.fiscal_year = cur_frm.doc.fiscal_year;
-
-				var d1 = frappe.model.add_child(jv, 'Journal Entry Account', 'accounts');
-				d1.debit = cur_frm.doc.total_sanctioned_amount;
-				d1.against_expense_claim = cur_frm.doc.name;
+				var expense = cur_frm.doc.expenses || [];
+				for(var i = 0; i < expense.length; i++){
+					var d1 = frappe.model.add_child(jv, 'Journal Entry Account', 'accounts');
+					d1.debit = expense[i].sanctioned_amount;
+					d1.account = expense[i].default_account;
+					d1.against_expense_claim = cur_frm.doc.name;
+				}
 
 				// credit to bank
 				var d1 = frappe.model.add_child(jv, 'Journal Entry Account', 'accounts');
@@ -43,6 +46,7 @@
 
 cur_frm.add_fetch('employee', 'company', 'company');
 cur_frm.add_fetch('employee','employee_name','employee_name');
+cur_frm.add_fetch('expense_type', 'default_account', 'default_account');
 
 cur_frm.cscript.onload = function(doc,cdt,cdn) {
 	if(!doc.approval_status)
diff --git a/erpnext/hr/doctype/expense_claim_detail/expense_claim_detail.json b/erpnext/hr/doctype/expense_claim_detail/expense_claim_detail.json
index c6123ee..9522d94 100644
--- a/erpnext/hr/doctype/expense_claim_detail/expense_claim_detail.json
+++ b/erpnext/hr/doctype/expense_claim_detail/expense_claim_detail.json
@@ -35,6 +35,18 @@
    "width": "150px"
   }, 
   {
+   "depends_on": "expense_type", 
+   "fieldname": "default_account", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "label": "Default Account", 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1, 
+   "unique": 0
+  }, 
+  {
    "fieldname": "section_break_4", 
    "fieldtype": "Section Break", 
    "permlevel": 0, 
@@ -93,7 +105,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-04-08 06:18:47.539134", 
+ "modified": "2015-07-16 06:13:32.090048", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Expense Claim Detail", 
diff --git a/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json b/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json
index fc7e604..0b0d304 100644
--- a/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json
+++ b/erpnext/hr/doctype/expense_claim_type/expense_claim_type.json
@@ -18,6 +18,14 @@
    "search_index": 0
   }, 
   {
+   "fieldname": "default_account", 
+   "fieldtype": "Link", 
+   "label": "Default Account", 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "description", 
    "fieldtype": "Small Text", 
    "label": "Description", 
@@ -29,7 +37,7 @@
  ], 
  "icon": "icon-flag", 
  "idx": 1, 
- "modified": "2015-07-13 04:46:38.897484", 
+ "modified": "2015-07-15 08:57:23.069980", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Expense Claim Type", 
@@ -55,7 +63,7 @@
    "print": 0, 
    "read": 1, 
    "report": 0, 
-   "role": "Employee", 
+   "role": "All", 
    "share": 0, 
    "write": 0
   }
diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
index 1a70f45..d6f865b 100644
--- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
+++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
@@ -9,8 +9,13 @@
 def execute(filters=None):
 	if not filters: filters = {}
 
-	employee_filters = filters.get("company") and \
-		[["Employee", "company", "=", filters.get("company")]] or None
+	employee_filters = {
+		"status": "Active"
+	}
+	
+	if filters.get("company"):
+		filters["company"] = filters.company
+
 	employees = runreport(doctype="Employee", fields=["name", "employee_name", "department"],
 		filters=employee_filters, limit_page_length=None)
 
diff --git a/erpnext/patches/v4_0/fields_to_be_renamed.py b/erpnext/patches/v4_0/fields_to_be_renamed.py
index 2baab97..cc17697 100644
--- a/erpnext/patches/v4_0/fields_to_be_renamed.py
+++ b/erpnext/patches/v4_0/fields_to_be_renamed.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.model import rename_field
+from frappe.model.utils.rename_field import rename_field
 from frappe.modules import scrub, get_doctype_module
 
 rename_map = {
diff --git a/erpnext/patches/v5_0/rename_table_fieldnames.py b/erpnext/patches/v5_0/rename_table_fieldnames.py
index c26accbf..05d5c91 100644
--- a/erpnext/patches/v5_0/rename_table_fieldnames.py
+++ b/erpnext/patches/v5_0/rename_table_fieldnames.py
@@ -2,7 +2,7 @@
 # License: GNU General Public License v3. See license.txt
 
 import frappe
-from frappe.model import rename_field
+from frappe.model.utils.rename_field import rename_field
 from frappe.modules import scrub, get_doctype_module
 
 rename_map = {
diff --git a/erpnext/patches/v5_0/rename_total_fields.py b/erpnext/patches/v5_0/rename_total_fields.py
index cf95caa..6657dd8 100644
--- a/erpnext/patches/v5_0/rename_total_fields.py
+++ b/erpnext/patches/v5_0/rename_total_fields.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.model import rename_field
+from frappe.model.utils.rename_field import rename_field
 from frappe.modules import scrub, get_doctype_module
 
 selling_doctypes = ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice")
diff --git a/erpnext/projects/doctype/task/task.js b/erpnext/projects/doctype/task/task.js
index d9a611e..4e870fa 100644
--- a/erpnext/projects/doctype/task/task.js
+++ b/erpnext/projects/doctype/task/task.js
@@ -5,42 +5,59 @@
 
 cur_frm.add_fetch("project", "company", "company");
 
-erpnext.projects.Task = frappe.ui.form.Controller.extend({
-	setup: function() {
-		this.frm.fields_dict.project.get_query = function() {
+frappe.ui.form.on("Task", {
+	refresh: function(frm) {
+		var doc = frm.doc;
+		if(!doc.__islocal) {
+			if(frappe.model.can_read("Time Log")) {
+				frm.add_custom_button(__("Time Logs"), function() {
+					frappe.route_options = {"project": doc.project, "task": doc.name}
+					frappe.set_route("List", "Time Log");
+				}, "icon-list", true);
+			}
+			if(frappe.model.can_read("Expense Claim")) {
+				frm.add_custom_button(__("Expense Claims"), function() {
+					frappe.route_options = {"project": doc.project, "task": doc.name}
+					frappe.set_route("List", "Expense Claim");
+				}, "icon-list", true);
+			}
+
+			if(frm.perm[0].write) {
+				if(frm.doc.status==="Open") {
+					frm.add_custom_button("Close", function() {
+						frm.set_value("status", "Closed");
+						frm.save();
+					});
+				} else {
+					frm.add_custom_button("Reopen", function() {
+						frm.set_value("status", "Open");
+						frm.save();
+					});
+				}
+			}
+		}
+	},
+
+	setup: function(frm) {
+		frm.fields_dict.project.get_query = function() {
 			return {
 				query: "erpnext.projects.doctype.task.task.get_project"
 			}
 		};
 	},
 
-	project: function() {
-		if(this.frm.doc.project) {
-			return get_server_fields('get_project_details', '','', this.frm.doc, this.frm.doc.doctype, 
-				this.frm.doc.name, 1);
+	project: function(frm) {
+		if(frm.doc.project) {
+			return get_server_fields('get_project_details', '','', frm.doc, frm.doc.doctype,
+				frm.doc.name, 1);
 		}
 	},
 
-	validate: function() {
-		this.frm.doc.project && frappe.model.remove_from_locals("Project",
-			this.frm.doc.project);
+	validate: function(frm) {
+		frm.doc.project && frappe.model.remove_from_locals("Project",
+			frm.doc.project);
 	},
-	
-	refresh: function(doc) {
-		if(!doc.__islocal) {
-			cur_frm.add_custom_button(__("Time Logs"), function() {
-				frappe.route_options = {"project": doc.project, "task": doc.name}
-				frappe.set_route("List", "Time Log");
-			}, "icon-list", true);
-			cur_frm.add_custom_button(__("Expense Claims"), function() {
-				frappe.route_options = {"project": doc.project, "task": doc.name}
-				frappe.set_route("List", "Expense Claim");
-			}, "icon-list", true);
-		}
-	}
+
 });
 
 cur_frm.add_fetch('task', 'subject', 'subject');
-
-cur_frm.cscript = new erpnext.projects.Task({frm: cur_frm});
-
diff --git a/erpnext/public/css/erpnext.css b/erpnext/public/css/erpnext.css
index b5f2a2d..3c286b1 100644
--- a/erpnext/public/css/erpnext.css
+++ b/erpnext/public/css/erpnext.css
@@ -96,3 +96,8 @@
 .pos .tax-table {
   margin-bottom: 10px;
 }
+.erpnext-icon {
+  width: 24px;
+  margin-right: 0px;
+  margin-top: -3px;
+}
diff --git a/erpnext/public/images/erp-icon.svg b/erpnext/public/images/erp-icon.svg
new file mode 100644
index 0000000..b4e2a24
--- /dev/null
+++ b/erpnext/public/images/erp-icon.svg
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>

+<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->

+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"

+	 width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">

+<g>

+	<path fill="#7574FF" d="M512,448c0,35.2-28.8,64-64,64H64c-35.2,0-64-28.8-64-64V64C0,28.8,28.8,0,64,0h384c35.2,0,64,28.8,64,64

+		V448z"/>

+</g>

+<g>

+	<path fill="#FFFFFF" d="M150.483,371.684V141.15c0-15.167,9.534-25.133,23.833-25.133h162.5c13.866,0,20.8,6.933,20.8,18.633v2.6

+		c0,12.133-6.934,18.633-20.8,18.633h-141.7v78.434h109.634c14.3,0,20.8,6.066,20.8,17.767v1.3c0,12.133-6.934,18.633-20.8,18.633

+		H195.117v84.934h144.3c13.867,0,20.367,6.066,20.367,17.767v2.167c0,12.566-6.5,19.5-20.367,19.5h-165.1

+		C160.017,396.384,150.483,386.851,150.483,371.684z"/>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+<g>

+</g>

+</svg>

diff --git a/erpnext/public/js/conf.js b/erpnext/public/js/conf.js
index 6264019..af06b33 100644
--- a/erpnext/public/js/conf.js
+++ b/erpnext/public/js/conf.js
@@ -11,7 +11,7 @@
 		href="https://discuss.erpnext.com">Feedback</a></p>'
 
 
-	$('.navbar-home').html('ERPNext');
+	$('.navbar-home').html('<img class="erpnext-icon" src="/assets/erpnext/images/erp-icon.svg" />');
 
 	$('[data-link="docs"]').attr("href", "https://manual.erpnext.com")
 });
diff --git a/erpnext/public/less/erpnext.less b/erpnext/public/less/erpnext.less
index 830902a..3f839ee 100644
--- a/erpnext/public/less/erpnext.less
+++ b/erpnext/public/less/erpnext.less
@@ -120,3 +120,8 @@
 	margin-bottom: 10px;
 }
 
+.erpnext-icon {
+	width: 24px;
+	margin-right: 0px;
+	margin-top: -3px;
+}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 7f0b386..fcdae4d 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -46,7 +46,6 @@
 
 			} else {
 				// un-stop
-				cur_frm.dashboard.set_headline_alert(__("Stopped"), "alert-danger", "icon-stop");
 				cur_frm.add_custom_button(__('Unstop'), cur_frm.cscript['Unstop Sales Order'], "icon-check");
 			}
 		}
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index ff027d7..010f5ea 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -57,7 +57,12 @@
 	def validate_item(self):
 		item_det = frappe.db.sql("""select name, has_batch_no, docstatus,
 			is_stock_item, has_variants, stock_uom
-			from tabItem where name=%s""", self.item_code, as_dict=True)[0]
+			from tabItem where name=%s""", self.item_code, as_dict=True)
+
+		if not item_det:
+			frappe.throw(_("Item {0} not found").format(self.item_code))
+
+		item_det = item_det[0]
 
 		if item_det.is_stock_item != 'Yes':
 			frappe.throw(_("Item {0} must be a stock Item").format(self.item_code))
@@ -97,7 +102,7 @@
 	def scrub_posting_time(self):
 		if not self.posting_time or self.posting_time == '00:0':
 			self.posting_time = '00:00'
-			
+
 	def validate_batch(self):
 		if self.batch_no and self.voucher_type != "Stock Entry":
 			expiry_date = frappe.db.get_value("Batch", self.batch_no, "expiry_date")
diff --git a/setup.py b/setup.py
index 610b284..9cb39e1 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = "5.2.0"
+version = "5.2.1"
 
 with open("requirements.txt", "r") as f:
 	install_requires = f.readlines()