frappe.db.exist used
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 7f5c4e8..9308a3d 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -443,8 +443,11 @@
 						Pending Amount is {2}".format(d.idx, d.against_expense_claim, pending_amount)))
 						
 	def validate_credit_debit_note(self):
-		count = frappe.db.sql("select count(stock_entry) as c from `tabJournal Entry` where \
-			stock_entry = %s and docstatus = 1", self.stock_entry, as_dict=1)[0].c
+		count = frappe.db.exists({
+			"doctype": "Journal Entry",
+			"stock_entry":self.stock_entry,
+			"docstatus":1	
+		})
 		if count:
 			frappe.throw(_("{0} already made against stock entry {1}".format(self.voucher_type, self.stock_entry)))
 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 6863876..e52e005 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -35,9 +35,15 @@
 				item.update(get_available_qty(item.item_code,
 					item.s_warehouse))
 	
-		count = frappe.db.sql("select count(stock_entry) as c from `tabJournal Entry` \
-			where stock_entry = %s and docstatus = 1",self.name, as_dict=1)[0].c
-		self.get("__onload").credit_debit_note_exists = count 
+		count = frappe.db.exists({
+			"doctype": "Journal Entry",
+			"stock_entry":self.stock_entry,
+			"docstatus":1	
+		})
+		if count:
+			self.get("__onload").credit_debit_note_exists = 1
+		else:
+			self.get("__onload").credit_debit_note_exists = 0
 
 	def validate(self):
 		self.validate_posting_time()