Changed frappe.conn to frappe.db
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index ecc8cf7..9e75135 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -44,7 +44,7 @@
def validate_for_freezed_account(self):
for fieldname in ["customer", "supplier"]:
if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname):
- accounts = frappe.conn.get_values("Account",
+ accounts = frappe.db.get_values("Account",
{"master_type": fieldname.title(), "master_name": self.doc.fields[fieldname],
"company": self.doc.company}, "name")
if accounts:
@@ -60,7 +60,7 @@
fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
else "buying_price_list"
if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname):
- self.doc.price_list_currency = frappe.conn.get_value("Price List",
+ self.doc.price_list_currency = frappe.db.get_value("Price List",
self.doc.fields.get(fieldname), "currency")
if self.doc.price_list_currency == company_currency:
@@ -82,7 +82,7 @@
def get_exchange_rate(self, from_currency, to_currency):
exchange = "%s-%s" % (from_currency, to_currency)
- return flt(frappe.conn.get_value("Currency Exchange", exchange, "exchange_rate"))
+ return flt(frappe.db.get_value("Currency Exchange", exchange, "exchange_rate"))
def set_missing_item_details(self):
"""set missing item values"""
@@ -106,7 +106,7 @@
if not self.doc.fields.get(tax_master_field):
# get the default tax master
self.doc.fields[tax_master_field] = \
- frappe.conn.get_value(tax_master_doctype, {"is_default": 1})
+ frappe.db.get_value(tax_master_doctype, {"is_default": 1})
self.append_taxes_from_master(tax_parentfield, tax_master_field, tax_master_doctype)
@@ -393,11 +393,11 @@
def clear_unallocated_advances(self, childtype, parentfield):
self.doclist.remove_items({"parentfield": parentfield, "allocated_amount": ["in", [0, None, ""]]})
- frappe.conn.sql("""delete from `tab%s` where parentfield=%s and parent = %s
+ frappe.db.sql("""delete from `tab%s` where parentfield=%s and parent = %s
and ifnull(allocated_amount, 0) = 0""" % (childtype, '%s', '%s'), (parentfield, self.doc.name))
def get_advances(self, account_head, child_doctype, parentfield, dr_or_cr):
- res = frappe.conn.sql("""select t1.name as jv_no, t1.remark,
+ res = frappe.db.sql("""select t1.name as jv_no, t1.remark,
t2.%s as amount, t2.name as jv_detail_no
from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2
where t1.name = t2.parent and t2.account = %s and t2.is_advance = 'Yes'
@@ -426,13 +426,13 @@
for item in self.doclist.get({"parentfield": "entries"}):
if item.fields.get(item_ref_dn):
- ref_amt = flt(frappe.conn.get_value(ref_dt + " Item",
+ ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
item.fields[item_ref_dn], based_on), self.precision(based_on, item))
if not ref_amt:
frappe.msgprint(_("As amount for item") + ": " + item.item_code + _(" in ") +
ref_dt + _(" is zero, system will not check for over-billed"))
else:
- already_billed = frappe.conn.sql("""select sum(%s) from `tab%s`
+ already_billed = frappe.db.sql("""select sum(%s) from `tab%s`
where %s=%s and docstatus=1 and parent != %s""" %
(based_on, self.tname, item_ref_dn, '%s', '%s'),
(item.fields[item_ref_dn], self.doc.name))[0][0]
@@ -468,7 +468,7 @@
item_codes = list(set(item.item_code for item in
self.doclist.get({"parentfield": self.fname})))
if item_codes:
- stock_items = [r[0] for r in frappe.conn.sql("""select name
+ stock_items = [r[0] for r in frappe.db.sql("""select name
from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \
(", ".join((["%s"]*len(item_codes))),), item_codes)]
@@ -477,12 +477,12 @@
@property
def company_abbr(self):
if not hasattr(self, "_abbr"):
- self._abbr = frappe.conn.get_value("Company", self.doc.company, "abbr")
+ self._abbr = frappe.db.get_value("Company", self.doc.company, "abbr")
return self._abbr
def check_credit_limit(self, account):
- total_outstanding = frappe.conn.sql("""
+ total_outstanding = frappe.db.sql("""
select sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
from `tabGL Entry` where account = %s""", account)
@@ -493,4 +493,4 @@
@frappe.whitelist()
def get_tax_rate(account_head):
- return frappe.conn.get_value("Account", account_head, "tax_rate")
\ No newline at end of file
+ return frappe.db.get_value("Account", account_head, "tax_rate")
\ No newline at end of file