mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-23 23:19:20 +00:00
mass replace sql with webnotes.conn.sql
This commit is contained in:
@@ -22,14 +22,14 @@ class DocType(BuyingController):
|
||||
msgprint(_("You need to put at least one item in the item table."), raise_exception=True)
|
||||
|
||||
def get_supplier_details(self, name = ''):
|
||||
details = sql("select supplier_name,address from `tabSupplier` where name = '%s' and docstatus != 2" %(name), as_dict = 1)
|
||||
details = webnotes.conn.sql("select supplier_name,address from `tabSupplier` where name = '%s' and docstatus != 2" %(name), as_dict = 1)
|
||||
if details:
|
||||
ret = {
|
||||
'supplier_name' : details and details[0]['supplier_name'] or '',
|
||||
'supplier_address' : details and details[0]['address'] or ''
|
||||
}
|
||||
# ********** get primary contact details (this is done separately coz. , in case there is no primary contact thn it would not be able to fetch customer details in case of join query)
|
||||
contact_det = sql("select contact_name, contact_no, email_id from `tabContact` where supplier = '%s' and is_supplier = 1 and is_primary_contact = 'Yes' and docstatus != 2" %(name), as_dict = 1)
|
||||
contact_det = webnotes.conn.sql("select contact_name, contact_no, email_id from `tabContact` where supplier = '%s' and is_supplier = 1 and is_primary_contact = 'Yes' and docstatus != 2" %(name), as_dict = 1)
|
||||
ret['contact_person'] = contact_det and contact_det[0]['contact_name'] or ''
|
||||
return ret
|
||||
else:
|
||||
@@ -39,7 +39,7 @@ class DocType(BuyingController):
|
||||
# Get Available Qty at Warehouse
|
||||
def get_bin_details( self, arg = ''):
|
||||
arg = eval(arg)
|
||||
bin = sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (arg['item_code'], arg['warehouse']), as_dict=1)
|
||||
bin = webnotes.conn.sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (arg['item_code'], arg['warehouse']), as_dict=1)
|
||||
ret = { 'projected_qty' : bin and flt(bin[0]['projected_qty']) or 0 }
|
||||
return ret
|
||||
|
||||
@@ -69,7 +69,7 @@ class DocType(BuyingController):
|
||||
|
||||
# update last purchsae rate
|
||||
if last_purchase_rate:
|
||||
sql("update `tabItem` set last_purchase_rate = %s where name = %s",
|
||||
webnotes.conn.sql("update `tabItem` set last_purchase_rate = %s where name = %s",
|
||||
(flt(last_purchase_rate),d.item_code))
|
||||
|
||||
def get_last_purchase_rate(self, obj):
|
||||
@@ -106,7 +106,7 @@ class DocType(BuyingController):
|
||||
raise Exception
|
||||
|
||||
# udpate with latest quantities
|
||||
bin = sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
bin = webnotes.conn.sql("select projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
|
||||
f_lst ={'projected_qty': bin and flt(bin[0]['projected_qty']) or 0, 'ordered_qty': 0, 'received_qty' : 0}
|
||||
if d.doctype == 'Purchase Receipt Item':
|
||||
@@ -115,7 +115,7 @@ class DocType(BuyingController):
|
||||
if d.fields.has_key(x):
|
||||
d.fields[x] = f_lst[x]
|
||||
|
||||
item = sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s",
|
||||
item = webnotes.conn.sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s",
|
||||
d.item_code)
|
||||
if not item:
|
||||
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True)
|
||||
@@ -138,7 +138,7 @@ class DocType(BuyingController):
|
||||
# if is not stock item
|
||||
f = [d.schedule_date, d.item_code, d.description]
|
||||
|
||||
ch = sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code)
|
||||
ch = webnotes.conn.sql("select is_stock_item from `tabItem` where name = '%s'"%d.item_code)
|
||||
|
||||
if ch and ch[0][0] == 'Yes':
|
||||
# check for same items
|
||||
@@ -164,18 +164,18 @@ class DocType(BuyingController):
|
||||
# but if in Material Request uom KG it can change in PO
|
||||
|
||||
get_qty = (transaction == 'Material Request - Purchase Order') and 'qty * conversion_factor' or 'qty'
|
||||
qty = sql("select sum(%s) from `tab%s` where %s = '%s' and docstatus = 1 and parent != '%s'"% ( get_qty, curr_doctype, ref_tab_fname, ref_tab_dn, curr_parent_name))
|
||||
qty = webnotes.conn.sql("select sum(%s) from `tab%s` where %s = '%s' and docstatus = 1 and parent != '%s'"% ( get_qty, curr_doctype, ref_tab_fname, ref_tab_dn, curr_parent_name))
|
||||
qty = qty and flt(qty[0][0]) or 0
|
||||
|
||||
# get total qty of ref doctype
|
||||
#--------------------
|
||||
max_qty = sql("select qty from `tab%s` where name = '%s' and docstatus = 1"% (ref_doc_tname, ref_tab_dn))
|
||||
max_qty = webnotes.conn.sql("select qty from `tab%s` where name = '%s' and docstatus = 1"% (ref_doc_tname, ref_tab_dn))
|
||||
max_qty = max_qty and flt(max_qty[0][0]) or 0
|
||||
|
||||
return cstr(qty)+'~~~'+cstr(max_qty)
|
||||
|
||||
def check_for_stopped_status(self, doctype, docname):
|
||||
stopped = sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
|
||||
stopped = webnotes.conn.sql("select name from `tab%s` where name = '%s' and status = 'Stopped'" %
|
||||
( doctype, docname))
|
||||
if stopped:
|
||||
msgprint("One cannot do any transaction against %s : %s, it's status is 'Stopped'" %
|
||||
@@ -183,7 +183,7 @@ class DocType(BuyingController):
|
||||
|
||||
def check_docstatus(self, check, doctype, docname , detail_doctype = ''):
|
||||
if check == 'Next':
|
||||
submitted = sql("""select t1.name from `tab%s` t1,`tab%s` t2
|
||||
submitted = webnotes.conn.sql("""select t1.name from `tab%s` t1,`tab%s` t2
|
||||
where t1.name = t2.parent and t2.prevdoc_docname = %s and t1.docstatus = 1"""
|
||||
% (doctype, detail_doctype, '%s'), docname)
|
||||
if submitted:
|
||||
@@ -191,7 +191,7 @@ class DocType(BuyingController):
|
||||
+ _(" has already been submitted."), raise_exception=1)
|
||||
|
||||
if check == 'Previous':
|
||||
submitted = sql("""select name from `tab%s`
|
||||
submitted = webnotes.conn.sql("""select name from `tab%s`
|
||||
where docstatus = 1 and name = %s"""% (doctype, '%s'), docname)
|
||||
if not submitted:
|
||||
msgprint(cstr(doctype) + ": " + cstr(submitted[0][0])
|
||||
@@ -199,7 +199,7 @@ class DocType(BuyingController):
|
||||
|
||||
def get_rate(self, arg, obj):
|
||||
arg = eval(arg)
|
||||
rate = sql("select account_type, tax_rate from `tabAccount` where name = %s"
|
||||
rate = webnotes.conn.sql("select account_type, tax_rate from `tabAccount` where name = %s"
|
||||
, (arg['account_head']), as_dict=1)
|
||||
|
||||
return {'rate': rate and (rate[0]['account_type'] == 'Tax' \
|
||||
@@ -208,6 +208,6 @@ class DocType(BuyingController):
|
||||
def get_prevdoc_date(self, obj):
|
||||
for d in getlist(obj.doclist, obj.fname):
|
||||
if d.prevdoc_doctype and d.prevdoc_docname:
|
||||
dt = sql("select transaction_date from `tab%s` where name = %s"
|
||||
dt = webnotes.conn.sql("select transaction_date from `tab%s` where name = %s"
|
||||
% (d.prevdoc_doctype, '%s'), (d.prevdoc_docname))
|
||||
d.prevdoc_date = dt and dt[0][0].strftime('%Y-%m-%d') or ''
|
||||
@@ -130,8 +130,8 @@ class DocType(BuyingController):
|
||||
get_obj("Warehouse", d.warehouse).update_bin(args)
|
||||
|
||||
def check_modified_date(self):
|
||||
mod_db = sql("select modified from `tabPurchase Order` where name = '%s'" % self.doc.name)
|
||||
date_diff = sql("select TIMEDIFF('%s', '%s')" % ( mod_db[0][0],cstr(self.doc.modified)))
|
||||
mod_db = webnotes.conn.sql("select modified from `tabPurchase Order` where name = '%s'" % self.doc.name)
|
||||
date_diff = webnotes.conn.sql("select TIMEDIFF('%s', '%s')" % ( mod_db[0][0],cstr(self.doc.modified)))
|
||||
|
||||
if date_diff and date_diff[0][0]:
|
||||
msgprint(cstr(self.doc.doctype) +" => "+ cstr(self.doc.name) +" has been modified. Please Refresh. ")
|
||||
@@ -170,7 +170,7 @@ class DocType(BuyingController):
|
||||
pc_obj.check_docstatus(check = 'Next', doctype = 'Purchase Receipt', docname = self.doc.name, detail_doctype = 'Purchase Receipt Item')
|
||||
|
||||
# Check if Purchase Invoice has been submitted against current Purchase Order
|
||||
submitted = sql("select t1.name from `tabPurchase Invoice` t1,`tabPurchase Invoice Item` t2 where t1.name = t2.parent and t2.purchase_order = '%s' and t1.docstatus = 1" % self.doc.name)
|
||||
submitted = webnotes.conn.sql("select t1.name from `tabPurchase Invoice` t1,`tabPurchase Invoice Item` t2 where t1.name = t2.parent and t2.purchase_order = '%s' and t1.docstatus = 1" % self.doc.name)
|
||||
if submitted:
|
||||
msgprint("Purchase Invoice : " + cstr(submitted[0][0]) + " has already been submitted !")
|
||||
raise Exception
|
||||
|
||||
@@ -28,7 +28,7 @@ class DocType(TransactionBase):
|
||||
self.doc.name = make_autoname(self.doc.naming_series + '.#####')
|
||||
|
||||
def update_credit_days_limit(self):
|
||||
sql("""update tabAccount set credit_days = %s where name = %s""",
|
||||
webnotes.conn.sql("""update tabAccount set credit_days = %s where name = %s""",
|
||||
(cint(self.doc.credit_days), self.doc.name + " - " + self.get_company_abbr()))
|
||||
|
||||
def on_update(self):
|
||||
@@ -42,7 +42,7 @@ class DocType(TransactionBase):
|
||||
self.update_credit_days_limit()
|
||||
|
||||
def get_payables_group(self):
|
||||
g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
|
||||
g = webnotes.conn.sql("select payables_group from tabCompany where name=%s", self.doc.company)
|
||||
g = g and g[0][0] or ''
|
||||
if not g:
|
||||
msgprint("Update Company master, assign a default group for Payables")
|
||||
@@ -64,14 +64,14 @@ class DocType(TransactionBase):
|
||||
msgprint(_("Created Group ") + ac)
|
||||
|
||||
def get_company_abbr(self):
|
||||
return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||
return webnotes.conn.sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
|
||||
|
||||
def get_parent_account(self, abbr):
|
||||
if (not self.doc.supplier_type):
|
||||
msgprint("Supplier Type is mandatory")
|
||||
raise Exception
|
||||
|
||||
if not sql("select name from tabAccount where name=%s and debit_or_credit = 'Credit' and ifnull(is_pl_account, 'No') = 'No'", (self.doc.supplier_type + " - " + abbr)):
|
||||
if not webnotes.conn.sql("select name from tabAccount where name=%s and debit_or_credit = 'Credit' and ifnull(is_pl_account, 'No') = 'No'", (self.doc.supplier_type + " - " + abbr)):
|
||||
|
||||
# if not group created , create it
|
||||
self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
|
||||
@@ -89,7 +89,7 @@ class DocType(TransactionBase):
|
||||
abbr = self.get_company_abbr()
|
||||
parent_account = self.get_parent_account(abbr)
|
||||
|
||||
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
|
||||
if not webnotes.conn.sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
|
||||
ac_bean = webnotes.bean({
|
||||
"doctype": "Account",
|
||||
'account_name': self.doc.name,
|
||||
@@ -120,15 +120,15 @@ class DocType(TransactionBase):
|
||||
|
||||
def get_contacts(self,nm):
|
||||
if nm:
|
||||
contact_details =webnotes.conn.convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
|
||||
contact_details =webnotes.conn.convert_to_lists(webnotes.conn.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
|
||||
|
||||
return contact_details
|
||||
else:
|
||||
return ''
|
||||
|
||||
def delete_supplier_address(self):
|
||||
for rec in sql("select * from `tabAddress` where supplier=%s", (self.doc.name,), as_dict=1):
|
||||
sql("delete from `tabAddress` where name=%s",(rec['name']))
|
||||
for rec in webnotes.conn.sql("select * from `tabAddress` where supplier=%s", (self.doc.name,), as_dict=1):
|
||||
webnotes.conn.sql("delete from `tabAddress` where name=%s",(rec['name']))
|
||||
|
||||
def delete_supplier_contact(self):
|
||||
for contact in webnotes.conn.sql_list("""select name from `tabContact`
|
||||
@@ -137,7 +137,7 @@ class DocType(TransactionBase):
|
||||
|
||||
def delete_supplier_account(self):
|
||||
"""delete supplier's ledger if exist and check balance before deletion"""
|
||||
acc = sql("select name from `tabAccount` where master_type = 'Supplier' \
|
||||
acc = webnotes.conn.sql("select name from `tabAccount` where master_type = 'Supplier' \
|
||||
and master_name = %s and docstatus < 2", self.doc.name)
|
||||
if acc:
|
||||
from webnotes.model import delete_doc
|
||||
@@ -160,7 +160,7 @@ class DocType(TransactionBase):
|
||||
('Purchase Receipt', 'supplier'),
|
||||
('Serial No', 'supplier')]
|
||||
for rec in update_fields:
|
||||
sql("update `tab%s` set supplier_name = %s where `%s` = %s" % \
|
||||
webnotes.conn.sql("update `tab%s` set supplier_name = %s where `%s` = %s" % \
|
||||
(rec[0], '%s', rec[1], '%s'), (new, old))
|
||||
|
||||
for account in webnotes.conn.sql("""select name, account_name from
|
||||
|
||||
Reference in New Issue
Block a user