From 50763d58ce382d8da0d681bb0634500e9b2cd958 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Mon, 12 Jan 2015 12:17:32 +0530 Subject: [PATCH] frappe.db.exist used --- .../accounts/doctype/journal_entry/journal_entry.py | 7 +++++-- erpnext/stock/doctype/stock_entry/stock_entry.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 7f5c4e807b..9308a3d7b0 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -443,8 +443,11 @@ class JournalEntry(AccountsController): 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 6863876eba..e52e005a6a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -35,9 +35,15 @@ class StockEntry(StockController): 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()