diff --git a/erpnext/accounts/doctype/c_form/c_form.py b/erpnext/accounts/doctype/c_form/c_form.py index 11d05470aa..e0f008f8ad 100644 --- a/erpnext/accounts/doctype/c_form/c_form.py +++ b/erpnext/accounts/doctype/c_form/c_form.py @@ -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])) diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js index 5316b587e1..4bdcd9e0c7 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js @@ -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 }, ] -} \ No newline at end of file +} diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py index 2b1923b11f..05cde6aab0 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py @@ -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] diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 1a09d38bf7..75825fcb7e 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -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` diff --git a/erpnext/utilities/__init__.py b/erpnext/utilities/__init__.py index e96ae83c8a..bfb3fe4bdf 100644 --- a/erpnext/utilities/__init__.py +++ b/erpnext/utilities/__init__.py @@ -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