mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 07:29:22 +00:00
mass replace sql with webnotes.conn.sql
This commit is contained in:
@@ -60,7 +60,7 @@ class DocType:
|
||||
self.doc.save()
|
||||
|
||||
def get_first_sle(self):
|
||||
sle = sql("""
|
||||
sle = webnotes.conn.sql("""
|
||||
select * from `tabStock Ledger Entry`
|
||||
where item_code = %s
|
||||
and warehouse = %s
|
||||
|
||||
@@ -57,7 +57,7 @@ class DocType(SellingController):
|
||||
def set_actual_qty(self):
|
||||
for d in getlist(self.doclist, 'delivery_note_details'):
|
||||
if d.item_code and d.warehouse:
|
||||
actual_qty = sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (d.item_code, d.warehouse))
|
||||
actual_qty = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (d.item_code, d.warehouse))
|
||||
d.actual_qty = actual_qty and flt(actual_qty[0][0]) or 0
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ class DocType(SellingController):
|
||||
def validate_proj_cust(self):
|
||||
"""check for does customer belong to same project as entered.."""
|
||||
if self.doc.project_name and self.doc.customer:
|
||||
res = sql("select name from `tabProject` where name = '%s' and (customer = '%s' or ifnull(customer,'')='')"%(self.doc.project_name, self.doc.customer))
|
||||
res = webnotes.conn.sql("select name from `tabProject` where name = '%s' and (customer = '%s' or ifnull(customer,'')='')"%(self.doc.project_name, self.doc.customer))
|
||||
if not res:
|
||||
msgprint("Customer - %s does not belong to project - %s. \n\nIf you want to use project for multiple customers then please make customer details blank in project - %s."%(self.doc.customer,self.doc.project_name,self.doc.project_name))
|
||||
raise Exception
|
||||
@@ -167,11 +167,11 @@ class DocType(SellingController):
|
||||
|
||||
def update_current_stock(self):
|
||||
for d in getlist(self.doclist, 'delivery_note_details'):
|
||||
bin = sql("select actual_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
bin = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0
|
||||
|
||||
for d in getlist(self.doclist, 'packing_details'):
|
||||
bin = sql("select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
bin = webnotes.conn.sql("select actual_qty, projected_qty from `tabBin` where item_code = %s and warehouse = %s", (d.item_code, d.warehouse), as_dict = 1)
|
||||
d.actual_qty = bin and flt(bin[0]['actual_qty']) or 0
|
||||
d.projected_qty = bin and flt(bin[0]['projected_qty']) or 0
|
||||
|
||||
@@ -266,12 +266,12 @@ class DocType(SellingController):
|
||||
webnotes.msgprint("Packing Error:\n" + err_msg, raise_exception=1)
|
||||
|
||||
def check_next_docstatus(self):
|
||||
submit_rv = sql("select t1.name from `tabSales Invoice` t1,`tabSales Invoice Item` t2 where t1.name = t2.parent and t2.delivery_note = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
submit_rv = webnotes.conn.sql("select t1.name from `tabSales Invoice` t1,`tabSales Invoice Item` t2 where t1.name = t2.parent and t2.delivery_note = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
if submit_rv:
|
||||
msgprint("Sales Invoice : " + cstr(submit_rv[0][0]) + " has already been submitted !")
|
||||
raise Exception , "Validation Error."
|
||||
|
||||
submit_in = sql("select t1.name from `tabInstallation Note` t1, `tabInstallation Note Item` t2 where t1.name = t2.parent and t2.prevdoc_docname = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
submit_in = webnotes.conn.sql("select t1.name from `tabInstallation Note` t1, `tabInstallation Note Item` t2 where t1.name = t2.parent and t2.prevdoc_docname = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
if submit_in:
|
||||
msgprint("Installation Note : "+cstr(submit_in[0][0]) +" has already been submitted !")
|
||||
raise Exception , "Validation Error."
|
||||
|
||||
@@ -32,7 +32,7 @@ class DocType:
|
||||
self.doclist = self.doc.clear_table(self.doclist,'lc_pr_details',1)
|
||||
self.check_mandatory()
|
||||
|
||||
pr = sql("select name from `tabPurchase Receipt` where docstatus = 1 and posting_date >= '%s' and posting_date <= '%s' and currency = '%s' order by name " % (self.doc.from_pr_date, self.doc.to_pr_date, self.doc.currency), as_dict = 1)
|
||||
pr = webnotes.conn.sql("select name from `tabPurchase Receipt` where docstatus = 1 and posting_date >= '%s' and posting_date <= '%s' and currency = '%s' order by name " % (self.doc.from_pr_date, self.doc.to_pr_date, self.doc.currency), as_dict = 1)
|
||||
if len(pr)>200:
|
||||
msgprint("Please enter date of shorter duration as there are too many purchase receipt, hence it cannot be loaded.", raise_exception=1)
|
||||
|
||||
@@ -50,14 +50,14 @@ class DocType:
|
||||
|
||||
def validate_selected_pr(self):
|
||||
"""Validate selected PR as submitted"""
|
||||
invalid_pr = sql("SELECT name FROM `tabPurchase Receipt` WHERE docstatus != 1 and name in (%s)" % ("'" + "', '".join(self.selected_pr) + "'"))
|
||||
invalid_pr = webnotes.conn.sql("SELECT name FROM `tabPurchase Receipt` WHERE docstatus != 1 and name in (%s)" % ("'" + "', '".join(self.selected_pr) + "'"))
|
||||
if invalid_pr:
|
||||
msgprint("Selected purchase receipts must be submitted. Following PR are not submitted: %s" % invalid_pr, raise_exception=1)
|
||||
|
||||
|
||||
def get_total_amt(self):
|
||||
""" Get sum of net total of all selected PR"""
|
||||
return sql("SELECT SUM(net_total) FROM `tabPurchase Receipt` WHERE name in (%s)" % ("'" + "', '".join(self.selected_pr) + "'"))[0][0]
|
||||
return webnotes.conn.sql("SELECT SUM(net_total) FROM `tabPurchase Receipt` WHERE name in (%s)" % ("'" + "', '".join(self.selected_pr) + "'"))[0][0]
|
||||
|
||||
|
||||
def add_charges_in_pr(self):
|
||||
@@ -73,7 +73,7 @@ class DocType:
|
||||
self.prwise_cost[pr] = self.prwise_cost.get(pr, 0) + amt
|
||||
cumulative_grand_total += amt
|
||||
|
||||
pr_oc_row = sql("select name from `tabPurchase Taxes and Charges` where parent = %s and category = 'Valuation' and add_deduct_tax = 'Add' and charge_type = 'Actual' and account_head = %s",(pr, lc.account_head))
|
||||
pr_oc_row = webnotes.conn.sql("select name from `tabPurchase Taxes and Charges` where parent = %s and category = 'Valuation' and add_deduct_tax = 'Add' and charge_type = 'Actual' and account_head = %s",(pr, lc.account_head))
|
||||
if not pr_oc_row: # add if not exists
|
||||
ch = addchild(pr_obj.doc, 'purchase_tax_details', 'Purchase Taxes and Charges')
|
||||
ch.category = 'Valuation'
|
||||
@@ -88,7 +88,7 @@ class DocType:
|
||||
ch.idx = 500 # add at the end
|
||||
ch.save(1)
|
||||
else: # overwrite if exists
|
||||
sql("update `tabPurchase Taxes and Charges` set rate = %s, tax_amount = %s where name = %s and parent = %s ", (amt, amt, pr_oc_row[0][0], pr))
|
||||
webnotes.conn.sql("update `tabPurchase Taxes and Charges` set rate = %s, tax_amount = %s where name = %s and parent = %s ", (amt, amt, pr_oc_row[0][0], pr))
|
||||
|
||||
|
||||
def reset_other_charges(self, pr_obj):
|
||||
@@ -200,9 +200,9 @@ class DocType:
|
||||
d.save()
|
||||
if d.serial_no:
|
||||
self.update_serial_no(d.serial_no, d.valuation_rate)
|
||||
sql("update `tabStock Ledger Entry` set incoming_rate = '%s' where voucher_detail_no = '%s'"%(flt(d.valuation_rate), d.name))
|
||||
webnotes.conn.sql("update `tabStock Ledger Entry` set incoming_rate = '%s' where voucher_detail_no = '%s'"%(flt(d.valuation_rate), d.name))
|
||||
|
||||
res = sql("""select item_code, warehouse, posting_date, posting_time
|
||||
res = webnotes.conn.sql("""select item_code, warehouse, posting_date, posting_time
|
||||
from `tabStock Ledger Entry` where voucher_detail_no = %s LIMIT 1""",
|
||||
d.name, as_dict=1)
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ class DocType(BuyingController):
|
||||
|
||||
def validate_inspection(self):
|
||||
for d in getlist(self.doclist, 'purchase_receipt_details'): #Enter inspection date for all items that require inspection
|
||||
ins_reqd = sql("select inspection_required from `tabItem` where name = %s",
|
||||
ins_reqd = webnotes.conn.sql("select inspection_required from `tabItem` where name = %s",
|
||||
(d.item_code,), as_dict = 1)
|
||||
ins_reqd = ins_reqd and ins_reqd[0]['inspection_required'] or 'No'
|
||||
if ins_reqd == 'Yes' and not d.qa_no:
|
||||
@@ -269,7 +269,7 @@ class DocType(BuyingController):
|
||||
sr.save()
|
||||
|
||||
def check_next_docstatus(self):
|
||||
submit_rv = sql("select t1.name from `tabPurchase Invoice` t1,`tabPurchase Invoice Item` t2 where t1.name = t2.parent and t2.purchase_receipt = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
submit_rv = webnotes.conn.sql("select t1.name from `tabPurchase Invoice` t1,`tabPurchase Invoice Item` t2 where t1.name = t2.parent and t2.purchase_receipt = '%s' and t1.docstatus = 1" % (self.doc.name))
|
||||
if submit_rv:
|
||||
msgprint("Purchase Invoice : " + cstr(self.submit_rv[0][0]) + " has already been submitted !")
|
||||
raise Exception , "Validation Error."
|
||||
@@ -282,7 +282,7 @@ class DocType(BuyingController):
|
||||
# 1.Check if Purchase Invoice has been submitted against current Purchase Order
|
||||
# pc_obj.check_docstatus(check = 'Next', doctype = 'Purchase Invoice', docname = self.doc.name, detail_doctype = 'Purchase Invoice Item')
|
||||
|
||||
submitted = sql("select t1.name from `tabPurchase Invoice` t1,`tabPurchase Invoice Item` t2 where t1.name = t2.parent and t2.purchase_receipt = '%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_receipt = '%s' and t1.docstatus = 1" % self.doc.name)
|
||||
if submitted:
|
||||
msgprint("Purchase Invoice : " + cstr(submitted[0][0]) + " has already been submitted !")
|
||||
raise Exception
|
||||
@@ -313,7 +313,7 @@ class DocType(BuyingController):
|
||||
def get_current_stock(self):
|
||||
for d in getlist(self.doclist, 'pr_raw_material_details'):
|
||||
if self.doc.supplier_warehouse:
|
||||
bin = sql("select actual_qty from `tabBin` where item_code = %s and warehouse = %s", (d.rm_item_code, self.doc.supplier_warehouse), as_dict = 1)
|
||||
bin = webnotes.conn.sql("select actual_qty from `tabBin` where item_code = %s and warehouse = %s", (d.rm_item_code, self.doc.supplier_warehouse), as_dict = 1)
|
||||
d.current_stock = bin and flt(bin[0]['actual_qty']) or 0
|
||||
|
||||
|
||||
|
||||
@@ -387,7 +387,7 @@ class DocType(StockController):
|
||||
def get_item_details(self, arg):
|
||||
arg = json.loads(arg)
|
||||
|
||||
item = sql("""select stock_uom, description, item_name from `tabItem`
|
||||
item = webnotes.conn.sql("""select stock_uom, description, item_name from `tabItem`
|
||||
where name = %s and (ifnull(end_of_life,'')='' or end_of_life ='0000-00-00'
|
||||
or end_of_life > now())""", (arg.get('item_code')), as_dict = 1)
|
||||
if not item:
|
||||
@@ -411,7 +411,7 @@ class DocType(StockController):
|
||||
|
||||
def get_uom_details(self, arg = ''):
|
||||
arg, ret = eval(arg), {}
|
||||
uom = sql("""select conversion_factor from `tabUOM Conversion Detail`
|
||||
uom = webnotes.conn.sql("""select conversion_factor from `tabUOM Conversion Detail`
|
||||
where parent = %s and uom = %s""", (arg['item_code'], arg['uom']), as_dict = 1)
|
||||
if not uom:
|
||||
msgprint("There is no Conversion Factor for UOM '%s' in Item '%s'" % (arg['uom'],
|
||||
@@ -522,7 +522,7 @@ class DocType(StockController):
|
||||
|
||||
if self.doc.use_multi_level_bom:
|
||||
# get all raw materials with sub assembly childs
|
||||
fl_bom_sa_child_item = sql("""select
|
||||
fl_bom_sa_child_item = webnotes.conn.sql("""select
|
||||
fb.item_code,
|
||||
ifnull(sum(fb.qty_consumed_per_unit),0)*%s as qty,
|
||||
fb.description,
|
||||
@@ -542,7 +542,7 @@ class DocType(StockController):
|
||||
_make_items_dict(fl_bom_sa_child_item)
|
||||
else:
|
||||
# get only BOM items
|
||||
fl_bom_sa_items = sql("""select
|
||||
fl_bom_sa_items = webnotes.conn.sql("""select
|
||||
`tabItem`.item_code,
|
||||
ifnull(sum(`tabBOM Item`.qty_consumed_per_unit), 0) *%s as qty,
|
||||
`tabItem`.description,
|
||||
@@ -600,7 +600,7 @@ class DocType(StockController):
|
||||
|
||||
def get_issued_qty(self):
|
||||
issued_item_qty = {}
|
||||
result = sql("""select t1.item_code, sum(t1.qty)
|
||||
result = webnotes.conn.sql("""select t1.item_code, sum(t1.qty)
|
||||
from `tabStock Entry Detail` t1, `tabStock Entry` t2
|
||||
where t1.parent = t2.name and t2.production_order = %s and t2.docstatus = 1
|
||||
and t2.purpose = 'Material Transfer'
|
||||
@@ -666,7 +666,7 @@ class DocType(StockController):
|
||||
|
||||
def get_cust_addr(self):
|
||||
from utilities.transaction_base import get_default_address, get_address_display
|
||||
res = sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer)
|
||||
res = webnotes.conn.sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer)
|
||||
address_display = None
|
||||
customer_address = get_default_address("customer", self.doc.customer)
|
||||
if customer_address:
|
||||
@@ -687,7 +687,7 @@ class DocType(StockController):
|
||||
|
||||
def get_supp_addr(self):
|
||||
from utilities.transaction_base import get_default_address, get_address_display
|
||||
res = sql("""select supplier_name from `tabSupplier`
|
||||
res = webnotes.conn.sql("""select supplier_name from `tabSupplier`
|
||||
where name=%s""", self.doc.supplier)
|
||||
address_display = None
|
||||
supplier_address = get_default_address("customer", self.doc.customer)
|
||||
|
||||
@@ -33,7 +33,7 @@ class DocType:
|
||||
msgprint("Please Enter Conversion Factor.")
|
||||
raise Exception
|
||||
|
||||
stock_uom = sql("select stock_uom from `tabItem` where name = '%s'" % self.doc.item_code)
|
||||
stock_uom = webnotes.conn.sql("select stock_uom from `tabItem` where name = '%s'" % self.doc.item_code)
|
||||
stock_uom = stock_uom and stock_uom[0][0]
|
||||
if cstr(self.doc.new_stock_uom) == cstr(stock_uom):
|
||||
msgprint("Item Master is already updated with New Stock UOM " + cstr(self.doc.new_stock_uom))
|
||||
@@ -49,9 +49,9 @@ class DocType:
|
||||
def update_bin(self):
|
||||
# update bin
|
||||
if flt(self.doc.conversion_factor) != flt(1):
|
||||
sql("update `tabBin` set stock_uom = '%s' , indented_qty = ifnull(indented_qty,0) * %s, ordered_qty = ifnull(ordered_qty,0) * %s, reserved_qty = ifnull(reserved_qty,0) * %s, planned_qty = ifnull(planned_qty,0) * %s, projected_qty = actual_qty + ordered_qty + indented_qty + planned_qty - reserved_qty where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.item_code) )
|
||||
webnotes.conn.sql("update `tabBin` set stock_uom = '%s' , indented_qty = ifnull(indented_qty,0) * %s, ordered_qty = ifnull(ordered_qty,0) * %s, reserved_qty = ifnull(reserved_qty,0) * %s, planned_qty = ifnull(planned_qty,0) * %s, projected_qty = actual_qty + ordered_qty + indented_qty + planned_qty - reserved_qty where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.item_code) )
|
||||
else:
|
||||
sql("update `tabBin` set stock_uom = '%s' where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.item_code) )
|
||||
webnotes.conn.sql("update `tabBin` set stock_uom = '%s' where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.item_code) )
|
||||
|
||||
# acknowledge user
|
||||
msgprint(" All Bins Updated Successfully.")
|
||||
@@ -61,16 +61,16 @@ class DocType:
|
||||
from stock.stock_ledger import update_entries_after
|
||||
|
||||
if flt(self.doc.conversion_factor) != flt(1):
|
||||
sql("update `tabStock Ledger Entry` set stock_uom = '%s', actual_qty = ifnull(actual_qty,0) * '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.item_code))
|
||||
webnotes.conn.sql("update `tabStock Ledger Entry` set stock_uom = '%s', actual_qty = ifnull(actual_qty,0) * '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.item_code))
|
||||
else:
|
||||
sql("update `tabStock Ledger Entry` set stock_uom = '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
|
||||
webnotes.conn.sql("update `tabStock Ledger Entry` set stock_uom = '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
|
||||
|
||||
# acknowledge user
|
||||
msgprint("Stock Ledger Entries Updated Successfully.")
|
||||
|
||||
# update item valuation
|
||||
if flt(self.doc.conversion_factor) != flt(1):
|
||||
wh = sql("select name from `tabWarehouse`")
|
||||
wh = webnotes.conn.sql("select name from `tabWarehouse`")
|
||||
for w in wh:
|
||||
update_entries_after({"item_code": self.doc.item_code, "warehouse": w[0]})
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class DocType:
|
||||
|
||||
def get_bin(self, item_code, warehouse=None):
|
||||
warehouse = warehouse or self.doc.name
|
||||
bin = sql("select name from tabBin where item_code = %s and \
|
||||
bin = webnotes.conn.sql("select name from tabBin where item_code = %s and \
|
||||
warehouse = %s", (item_code, warehouse))
|
||||
bin = bin and bin[0][0] or ''
|
||||
if not bin:
|
||||
@@ -163,22 +163,22 @@ class DocType:
|
||||
|
||||
def on_trash(self):
|
||||
# delete bin
|
||||
bins = sql("select * from `tabBin` where warehouse = %s", self.doc.name, as_dict=1)
|
||||
bins = webnotes.conn.sql("select * from `tabBin` where warehouse = %s", self.doc.name, as_dict=1)
|
||||
for d in bins:
|
||||
if d['actual_qty'] or d['reserved_qty'] or d['ordered_qty'] or \
|
||||
d['indented_qty'] or d['projected_qty'] or d['planned_qty']:
|
||||
msgprint("""Warehouse: %s can not be deleted as qty exists for item: %s"""
|
||||
% (self.doc.name, d['item_code']), raise_exception=1)
|
||||
else:
|
||||
sql("delete from `tabBin` where name = %s", d['name'])
|
||||
webnotes.conn.sql("delete from `tabBin` where name = %s", d['name'])
|
||||
|
||||
# delete cancelled sle
|
||||
if sql("""select name from `tabStock Ledger Entry`
|
||||
if webnotes.conn.sql("""select name from `tabStock Ledger Entry`
|
||||
where warehouse = %s and ifnull('is_cancelled', '') = 'No'""", self.doc.name):
|
||||
msgprint("""Warehosue can not be deleted as stock ledger entry
|
||||
exists for this warehouse.""", raise_exception=1)
|
||||
else:
|
||||
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
||||
|
||||
def on_rename(self, newdn, olddn, merge=False):
|
||||
if merge:
|
||||
|
||||
Reference in New Issue
Block a user