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,
|
||||
'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]))
|
||||
|
@ -11,7 +11,7 @@ frappe.query_reports["Bank Reconciliation Statement"] = {
|
||||
"reqd": 1,
|
||||
"get_query": function() {
|
||||
return {
|
||||
"query": "erpnext.accounts.utils.get_account_list",
|
||||
"query": "erpnext.accounts.utils.get_account_list",
|
||||
"filters": [
|
||||
['Account', 'account_type', 'in', 'Bank, Cash'],
|
||||
['Account', 'group_or_ledger', '=', 'Ledger'],
|
||||
@ -27,4 +27,4 @@ frappe.query_reports["Bank Reconciliation Statement"] = {
|
||||
"reqd": 1
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ from frappe.utils import flt
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
|
||||
if not filters.get("account"): return
|
||||
|
||||
columns = get_columns()
|
||||
data = get_entries(filters)
|
||||
|
||||
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
balance_as_per_company = get_balance_on(filters["account"], filters["report_date"])
|
||||
|
||||
@ -20,33 +21,33 @@ def execute(filters=None):
|
||||
total_credit += flt(d[5])
|
||||
|
||||
bank_bal = flt(balance_as_per_company) + flt(total_debit) - flt(total_credit)
|
||||
|
||||
|
||||
data += [
|
||||
get_balance_row("Balance as per company books", balance_as_per_company),
|
||||
["", "", "", "Amounts not reflected in bank", total_debit, total_credit],
|
||||
["", "", "", "Amounts not reflected in bank", total_debit, total_credit],
|
||||
get_balance_row("Balance as per bank", bank_bal)
|
||||
]
|
||||
|
||||
|
||||
return columns, data
|
||||
|
||||
|
||||
def get_columns():
|
||||
return ["Journal Voucher:Link/Journal Voucher:140", "Posting Date:Date:100",
|
||||
"Clearance Date:Date:110", "Against Account:Link/Account:200",
|
||||
return ["Journal Voucher:Link/Journal Voucher:140", "Posting Date:Date:100",
|
||||
"Clearance Date:Date:110", "Against Account:Link/Account:200",
|
||||
"Debit:Currency:120", "Credit:Currency:120"
|
||||
]
|
||||
|
||||
|
||||
def get_entries(filters):
|
||||
entries = frappe.db.sql("""select
|
||||
entries = frappe.db.sql("""select
|
||||
jv.name, jv.posting_date, jv.clearance_date, jvd.against_account, jvd.debit, jvd.credit
|
||||
from
|
||||
`tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
|
||||
where jvd.parent = jv.name and jv.docstatus=1
|
||||
and jvd.account = %(account)s and jv.posting_date <= %(report_date)s
|
||||
from
|
||||
`tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
|
||||
where jvd.parent = jv.name and jv.docstatus=1
|
||||
and jvd.account = %(account)s and jv.posting_date <= %(report_date)s
|
||||
and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s
|
||||
order by jv.name DESC""", filters, as_list=1)
|
||||
|
||||
|
||||
return entries
|
||||
|
||||
|
||||
def get_balance_row(label, amount):
|
||||
if amount > 0:
|
||||
return ["", "", "", label, amount, 0]
|
||||
|
@ -7,8 +7,7 @@ import frappe
|
||||
from frappe.utils import nowdate, cstr, flt, now, getdate, add_months
|
||||
from frappe import throw, _
|
||||
from frappe.utils import formatdate
|
||||
from erpnext.utilities import build_filter_conditions
|
||||
|
||||
import frappe.widgets.reportview
|
||||
|
||||
class FiscalYearError(frappe.ValidationError): pass
|
||||
class BudgetError(frappe.ValidationError): pass
|
||||
@ -197,26 +196,28 @@ def update_against_doc(d, jv_obj):
|
||||
jv_obj.save()
|
||||
|
||||
def get_account_list(doctype, txt, searchfield, start, page_len, filters):
|
||||
if not filters.get("group_or_ledger"):
|
||||
filters["group_or_ledger"] = "Ledger"
|
||||
filters = add_group_or_ledger_filter("Account", filters)
|
||||
|
||||
conditions, filter_values = build_filter_conditions(filters)
|
||||
|
||||
return frappe.db.sql("""select name, parent_account from `tabAccount`
|
||||
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]))
|
||||
return frappe.widgets.reportview.execute("Account", filters = filters,
|
||||
fields = ["name", "parent_account"],
|
||||
limit_start=start, limit_page_length=page_len, as_list=True)
|
||||
|
||||
def get_cost_center_list(doctype, txt, searchfield, start, page_len, filters):
|
||||
if not filters.get("group_or_ledger"):
|
||||
filters["group_or_ledger"] = "Ledger"
|
||||
filters = add_group_or_ledger_filter("Cost Center", filters)
|
||||
|
||||
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`
|
||||
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 add_group_or_ledger_filter(doctype, filters):
|
||||
if isinstance(filters, dict):
|
||||
if not filters.get("group_or_ledger"):
|
||||
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):
|
||||
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):
|
||||
if status not in 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