use build_filter_conditions from db_query. Fixes #1679
This commit is contained in:
parent
10cb4799bc
commit
62ec60188b
@ -64,13 +64,3 @@ class CForm(Document):
|
|||||||
'net_total' : inv.net_total,
|
'net_total' : inv.net_total,
|
||||||
'grand_total' : inv.grand_total
|
'grand_total' : inv.grand_total
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_invoice_nos(doctype, txt, searchfield, start, page_len, filters):
|
|
||||||
from erpnext.utilities import build_filter_conditions
|
|
||||||
conditions, filter_values = build_filter_conditions(filters)
|
|
||||||
|
|
||||||
return frappe.db.sql("""select name from `tabSales Invoice` where docstatus = 1
|
|
||||||
and c_form_applicable = 'Yes' and ifnull(c_form_no, '') = '' %s
|
|
||||||
and %s like %s order by name limit %s, %s""" %
|
|
||||||
(conditions, searchfield, "%s", "%s", "%s"),
|
|
||||||
tuple(filter_values + ["%%%s%%" % txt, start, page_len]))
|
|
||||||
|
@ -7,6 +7,7 @@ from frappe.utils import flt
|
|||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters = {}
|
if not filters: filters = {}
|
||||||
|
if not filters.get("account"): return
|
||||||
|
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
data = get_entries(filters)
|
data = get_entries(filters)
|
||||||
|
@ -7,8 +7,7 @@ import frappe
|
|||||||
from frappe.utils import nowdate, cstr, flt, now, getdate, add_months
|
from frappe.utils import nowdate, cstr, flt, now, getdate, add_months
|
||||||
from frappe import throw, _
|
from frappe import throw, _
|
||||||
from frappe.utils import formatdate
|
from frappe.utils import formatdate
|
||||||
from erpnext.utilities import build_filter_conditions
|
import frappe.widgets.reportview
|
||||||
|
|
||||||
|
|
||||||
class FiscalYearError(frappe.ValidationError): pass
|
class FiscalYearError(frappe.ValidationError): pass
|
||||||
class BudgetError(frappe.ValidationError): pass
|
class BudgetError(frappe.ValidationError): pass
|
||||||
@ -197,26 +196,28 @@ def update_against_doc(d, jv_obj):
|
|||||||
jv_obj.save()
|
jv_obj.save()
|
||||||
|
|
||||||
def get_account_list(doctype, txt, searchfield, start, page_len, filters):
|
def get_account_list(doctype, txt, searchfield, start, page_len, filters):
|
||||||
if not filters.get("group_or_ledger"):
|
filters = add_group_or_ledger_filter("Account", filters)
|
||||||
filters["group_or_ledger"] = "Ledger"
|
|
||||||
|
|
||||||
conditions, filter_values = build_filter_conditions(filters)
|
return frappe.widgets.reportview.execute("Account", filters = filters,
|
||||||
|
fields = ["name", "parent_account"],
|
||||||
return frappe.db.sql("""select name, parent_account from `tabAccount`
|
limit_start=start, limit_page_length=page_len, as_list=True)
|
||||||
where docstatus < 2 %s and %s like %s order by name limit %s, %s""" %
|
|
||||||
(conditions, searchfield, "%s", "%s", "%s"),
|
|
||||||
tuple(filter_values + ["%%%s%%" % txt, start, page_len]))
|
|
||||||
|
|
||||||
def get_cost_center_list(doctype, txt, searchfield, start, page_len, filters):
|
def get_cost_center_list(doctype, txt, searchfield, start, page_len, filters):
|
||||||
if not filters.get("group_or_ledger"):
|
filters = add_group_or_ledger_filter("Cost Center", filters)
|
||||||
filters["group_or_ledger"] = "Ledger"
|
|
||||||
|
|
||||||
conditions, filter_values = build_filter_conditions(filters)
|
return frappe.widgets.reportview.execute("Cost Center", filters = filters,
|
||||||
|
fields = ["name", "parent_cost_center"],
|
||||||
|
limit_start=start, limit_page_length=page_len, as_list=True)
|
||||||
|
|
||||||
return frappe.db.sql("""select name, parent_cost_center from `tabCost Center`
|
def add_group_or_ledger_filter(doctype, filters):
|
||||||
where docstatus < 2 %s and %s like %s order by name limit %s, %s""" %
|
if isinstance(filters, dict):
|
||||||
(conditions, searchfield, "%s", "%s", "%s"),
|
if not filters.get("group_or_ledger"):
|
||||||
tuple(filter_values + ["%%%s%%" % txt, start, page_len]))
|
filters["group_or_ledger"] = "Ledger"
|
||||||
|
elif isinstance(filters, list):
|
||||||
|
if "group_or_ledger" not in [d[0] for d in filters]:
|
||||||
|
filters.append([doctype, "group_or_ledger", "=", "Ledger"])
|
||||||
|
|
||||||
|
return filters
|
||||||
|
|
||||||
def remove_against_link_from_jv(ref_type, ref_no, against_field):
|
def remove_against_link_from_jv(ref_type, ref_no, against_field):
|
||||||
linked_jv = frappe.db.sql_list("""select parent from `tabJournal Voucher Detail`
|
linked_jv = frappe.db.sql_list("""select parent from `tabJournal Voucher Detail`
|
||||||
|
@ -22,12 +22,3 @@ from frappe.utils import cint, comma_or
|
|||||||
def validate_status(status, options):
|
def validate_status(status, options):
|
||||||
if status not in options:
|
if status not in options:
|
||||||
frappe.throw(_("Status must be one of {0}").format(comma_or(options)))
|
frappe.throw(_("Status must be one of {0}").format(comma_or(options)))
|
||||||
|
|
||||||
def build_filter_conditions(filters):
|
|
||||||
conditions, filter_values = [], []
|
|
||||||
for key in filters:
|
|
||||||
conditions.append('`' + key + '` = %s')
|
|
||||||
filter_values.append(filters[key])
|
|
||||||
|
|
||||||
conditions = conditions and " and " + " and ".join(conditions) or ""
|
|
||||||
return conditions, filter_values
|
|
||||||
|
Loading…
Reference in New Issue
Block a user