Merge branch 'develop' into email-campaign
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 8f1dfbc..a617de3 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -121,7 +121,12 @@
 
 	allow_cost_center_in_entry_of_bs_account = get_allow_cost_center_in_entry_of_bs_account()
 
-	if cost_center and (allow_cost_center_in_entry_of_bs_account or acc.report_type =='Profit and Loss'):
+	if account:
+		report_type = acc.report_type
+	else:
+		report_type = ""
+
+	if cost_center and (allow_cost_center_in_entry_of_bs_account or report_type =='Profit and Loss'):
 		cc = frappe.get_doc("Cost Center", cost_center)
 		if cc.is_group:
 			cond.append(""" exists (
@@ -138,7 +143,7 @@
 		if not frappe.flags.ignore_account_permission:
 			acc.check_permission("read")
 
-		if acc.report_type == 'Profit and Loss':
+		if report_type == 'Profit and Loss':
 			# for pl accounts, get balance within a fiscal year
 			cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \
 				% year_start_date)
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 47c9f0a..57c063a 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -207,10 +207,10 @@
 			idx desc, name
 		limit %(start)s, %(page_len)s """.format(
 			fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
-			mcond=get_match_cond(doctype),
-			key=frappe.db.escape(searchfield)),
+			mcond=get_match_cond(doctype).replace('%', '%%'),
+			key=searchfield),
 		{
-			'txt': "%"+frappe.db.escape(txt)+"%",
+			'txt': '%' + txt + '%',
 			'_txt': txt.replace("%", ""),
 			'start': start or 0,
 			'page_len': page_len or 20
diff --git a/erpnext/hr/doctype/loan_application/loan_application.py b/erpnext/hr/doctype/loan_application/loan_application.py
index 67be9f2..58a362d 100644
--- a/erpnext/hr/doctype/loan_application/loan_application.py
+++ b/erpnext/hr/doctype/loan_application/loan_application.py
@@ -33,8 +33,8 @@
 				if self.repayment_amount - min_repayment_amount < 0:
 					frappe.throw(_("Repayment Amount must be greater than " \
 						+ str(flt(min_repayment_amount, 2))))
-				self.repayment_periods = math.ceil(math.log(self.repayment_amount) -
-					math.log(self.repayment_amount - min_repayment_amount) /(math.log(1 + monthly_interest_rate)))
+				self.repayment_periods = math.ceil((math.log(self.repayment_amount) -
+					math.log(self.repayment_amount - min_repayment_amount)) /(math.log(1 + monthly_interest_rate)))
 			else:
 				self.repayment_periods = self.loan_amount / self.repayment_amount
 
diff --git a/erpnext/hr/report/loan_repayment/loan_repayment.py b/erpnext/hr/report/loan_repayment/loan_repayment.py
index 9e310de..beca776 100644
--- a/erpnext/hr/report/loan_repayment/loan_repayment.py
+++ b/erpnext/hr/report/loan_repayment/loan_repayment.py
@@ -73,7 +73,7 @@
 def get_record():
 	data = []
 	loans = frappe.get_all("Loan",
-		filters=[("status", "=", "Fully Disbursed")],
+		filters=[("status", "=", "Disbursed")],
 		fields=["applicant", "applicant_name", "name", "loan_amount", "rate_of_interest",
 			"total_payment", "monthly_repayment_amount", "total_amount_paid"]
 	)