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]))
|
|
||||||
|
@ -11,7 +11,7 @@ frappe.query_reports["Bank Reconciliation Statement"] = {
|
|||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"get_query": function() {
|
"get_query": function() {
|
||||||
return {
|
return {
|
||||||
"query": "erpnext.accounts.utils.get_account_list",
|
"query": "erpnext.accounts.utils.get_account_list",
|
||||||
"filters": [
|
"filters": [
|
||||||
['Account', 'account_type', 'in', 'Bank, Cash'],
|
['Account', 'account_type', 'in', 'Bank, Cash'],
|
||||||
['Account', 'group_or_ledger', '=', 'Ledger'],
|
['Account', 'group_or_ledger', '=', 'Ledger'],
|
||||||
@ -27,4 +27,4 @@ frappe.query_reports["Bank Reconciliation Statement"] = {
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,11 @@ 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)
|
||||||
|
|
||||||
from erpnext.accounts.utils import get_balance_on
|
from erpnext.accounts.utils import get_balance_on
|
||||||
balance_as_per_company = get_balance_on(filters["account"], filters["report_date"])
|
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])
|
total_credit += flt(d[5])
|
||||||
|
|
||||||
bank_bal = flt(balance_as_per_company) + flt(total_debit) - flt(total_credit)
|
bank_bal = flt(balance_as_per_company) + flt(total_debit) - flt(total_credit)
|
||||||
|
|
||||||
data += [
|
data += [
|
||||||
get_balance_row("Balance as per company books", balance_as_per_company),
|
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)
|
get_balance_row("Balance as per bank", bank_bal)
|
||||||
]
|
]
|
||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
return ["Journal Voucher:Link/Journal Voucher:140", "Posting Date:Date:100",
|
return ["Journal Voucher:Link/Journal Voucher:140", "Posting Date:Date:100",
|
||||||
"Clearance Date:Date:110", "Against Account:Link/Account:200",
|
"Clearance Date:Date:110", "Against Account:Link/Account:200",
|
||||||
"Debit:Currency:120", "Credit:Currency:120"
|
"Debit:Currency:120", "Credit:Currency:120"
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_entries(filters):
|
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
|
jv.name, jv.posting_date, jv.clearance_date, jvd.against_account, jvd.debit, jvd.credit
|
||||||
from
|
from
|
||||||
`tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
|
`tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
|
||||||
where jvd.parent = jv.name and jv.docstatus=1
|
where jvd.parent = jv.name and jv.docstatus=1
|
||||||
and jvd.account = %(account)s and jv.posting_date <= %(report_date)s
|
and jvd.account = %(account)s and jv.posting_date <= %(report_date)s
|
||||||
and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s
|
and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s
|
||||||
order by jv.name DESC""", filters, as_list=1)
|
order by jv.name DESC""", filters, as_list=1)
|
||||||
|
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
def get_balance_row(label, amount):
|
def get_balance_row(label, amount):
|
||||||
if amount > 0:
|
if amount > 0:
|
||||||
return ["", "", "", label, 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.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