Changed frappe.conn to frappe.db
This commit is contained in:
@@ -20,7 +20,7 @@ class SellingController(StockController):
|
||||
check_active_sales_items(self)
|
||||
|
||||
def get_sender(self, comm):
|
||||
return frappe.conn.get_value('Sales Email Settings', None, 'email_id')
|
||||
return frappe.db.get_value('Sales Email Settings', None, 'email_id')
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
super(SellingController, self).set_missing_values(for_validate)
|
||||
@@ -73,7 +73,7 @@ class SellingController(StockController):
|
||||
from frappe.utils import money_in_words
|
||||
company_currency = get_company_currency(self.doc.company)
|
||||
|
||||
disable_rounded_total = cint(frappe.conn.get_value("Global Defaults", None,
|
||||
disable_rounded_total = cint(frappe.db.get_value("Global Defaults", None,
|
||||
"disable_rounded_total"))
|
||||
|
||||
if self.meta.get_field("in_words"):
|
||||
@@ -266,10 +266,10 @@ class SellingController(StockController):
|
||||
_("must be one of") + ": " + comma_or(valid_types), raise_exception=True)
|
||||
|
||||
def check_credit(self, grand_total):
|
||||
customer_account = frappe.conn.get_value("Account", {"company": self.doc.company,
|
||||
customer_account = frappe.db.get_value("Account", {"company": self.doc.company,
|
||||
"master_name": self.doc.customer}, "name")
|
||||
if customer_account:
|
||||
total_outstanding = frappe.conn.sql("""select
|
||||
total_outstanding = frappe.db.sql("""select
|
||||
sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
||||
from `tabGL Entry` where account = %s""", customer_account)
|
||||
total_outstanding = total_outstanding[0][0] if total_outstanding else 0
|
||||
@@ -280,7 +280,7 @@ class SellingController(StockController):
|
||||
|
||||
def validate_max_discount(self):
|
||||
for d in self.doclist.get({"parentfield": self.fname}):
|
||||
discount = flt(frappe.conn.get_value("Item", d.item_code, "max_discount"))
|
||||
discount = flt(frappe.db.get_value("Item", d.item_code, "max_discount"))
|
||||
|
||||
if discount and flt(d.discount_percentage) > discount:
|
||||
frappe.throw(_("You cannot give more than ") + cstr(discount) + "% " +
|
||||
@@ -293,7 +293,7 @@ class SellingController(StockController):
|
||||
reserved_qty_for_main_item = 0
|
||||
|
||||
if self.doc.doctype == "Sales Order":
|
||||
if (frappe.conn.get_value("Item", d.item_code, "is_stock_item") == 'Yes' or
|
||||
if (frappe.db.get_value("Item", d.item_code, "is_stock_item") == 'Yes' or
|
||||
self.has_sales_bom(d.item_code)) and not d.warehouse:
|
||||
frappe.throw(_("Please enter Reserved Warehouse for item ") +
|
||||
d.item_code + _(" as it is stock Item or packing item"))
|
||||
@@ -344,18 +344,18 @@ class SellingController(StockController):
|
||||
return il
|
||||
|
||||
def has_sales_bom(self, item_code):
|
||||
return frappe.conn.sql("""select name from `tabSales BOM`
|
||||
return frappe.db.sql("""select name from `tabSales BOM`
|
||||
where new_item_code=%s and docstatus != 2""", item_code)
|
||||
|
||||
def get_already_delivered_qty(self, dn, so, so_detail):
|
||||
qty = frappe.conn.sql("""select sum(qty) from `tabDelivery Note Item`
|
||||
qty = frappe.db.sql("""select sum(qty) from `tabDelivery Note Item`
|
||||
where prevdoc_detail_docname = %s and docstatus = 1
|
||||
and against_sales_order = %s
|
||||
and parent != %s""", (so_detail, so, dn))
|
||||
return qty and flt(qty[0][0]) or 0.0
|
||||
|
||||
def get_so_qty_and_warehouse(self, so_detail):
|
||||
so_item = frappe.conn.sql("""select qty, warehouse from `tabSales Order Item`
|
||||
so_item = frappe.db.sql("""select qty, warehouse from `tabSales Order Item`
|
||||
where name = %s and docstatus = 1""", so_detail, as_dict=1)
|
||||
so_qty = so_item and flt(so_item[0]["qty"]) or 0.0
|
||||
so_warehouse = so_item and so_item[0]["warehouse"] or ""
|
||||
@@ -364,7 +364,7 @@ class SellingController(StockController):
|
||||
def check_stop_sales_order(self, ref_fieldname):
|
||||
for d in self.doclist.get({"parentfield": self.fname}):
|
||||
if d.fields.get(ref_fieldname):
|
||||
status = frappe.conn.get_value("Sales Order", d.fields[ref_fieldname], "status")
|
||||
status = frappe.db.get_value("Sales Order", d.fields[ref_fieldname], "status")
|
||||
if status == "Stopped":
|
||||
frappe.throw(self.doc.doctype +
|
||||
_(" can not be created/modified against stopped Sales Order ") +
|
||||
@@ -373,11 +373,11 @@ class SellingController(StockController):
|
||||
def check_active_sales_items(obj):
|
||||
for d in obj.doclist.get({"parentfield": obj.fname}):
|
||||
if d.item_code:
|
||||
item = frappe.conn.sql("""select docstatus, is_sales_item,
|
||||
item = frappe.db.sql("""select docstatus, is_sales_item,
|
||||
is_service_item, income_account from tabItem where name = %s""",
|
||||
d.item_code, as_dict=True)[0]
|
||||
if item.is_sales_item == 'No' and item.is_service_item == 'No':
|
||||
frappe.throw(_("Item is neither Sales nor Service Item") + ": " + d.item_code)
|
||||
if d.income_account and not item.income_account:
|
||||
frappe.conn.set_value("Item", d.item_code, "income_account",
|
||||
frappe.db.set_value("Item", d.item_code, "income_account",
|
||||
d.income_account)
|
||||
|
||||
Reference in New Issue
Block a user