From 06757a19ef1df9262924094899fa81f21e6e19c5 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 4 Nov 2013 12:55:24 +0530 Subject: [PATCH] [minor] [query] expense and income account queries should exclude customer and supplier accounts --- accounts/doctype/purchase_invoice/purchase_invoice.py | 9 +++++++-- accounts/doctype/sales_invoice/sales_invoice.py | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index f3d359bd45..55776d9cdd 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -468,12 +468,17 @@ class DocType(BuyingController): @webnotes.whitelist() def get_expense_account(doctype, txt, searchfield, start, page_len, filters): from controllers.queries import get_match_cond - + + # expense account can be any Debit account, + # but can also be a Liability account with account_type='Expense Account' in special circumstances. + # Hence the first condition is an "OR" return webnotes.conn.sql("""select tabAccount.name from `tabAccount` where (tabAccount.debit_or_credit="Debit" - or tabAccount.account_type = "Expense Account") + or tabAccount.account_type = "Expense Account") and tabAccount.group_or_ledger="Ledger" and tabAccount.docstatus!=2 + and ifnull(tabAccount.master_type, "")="" + and ifnull(tabAccount.master_name, "")="" and tabAccount.company = '%(company)s' and tabAccount.%(key)s LIKE '%(txt)s' %(mcond)s""" % {'company': filters['company'], 'key': searchfield, diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 3ae74e481e..6c02bbea66 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -925,11 +925,16 @@ def get_bank_cash_account(mode_of_payment): def get_income_account(doctype, txt, searchfield, start, page_len, filters): from controllers.queries import get_match_cond + # income account can be any Credit account, + # but can also be a Asset account with account_type='Income Account' in special circumstances. + # Hence the first condition is an "OR" return webnotes.conn.sql("""select tabAccount.name from `tabAccount` where (tabAccount.debit_or_credit="Credit" or tabAccount.account_type = "Income Account") and tabAccount.group_or_ledger="Ledger" - and tabAccount.docstatus!=2 + and tabAccount.docstatus!=2 + and ifnull(tabAccount.master_type, "")="" + and ifnull(tabAccount.master_name, "")="" and tabAccount.company = '%(company)s' and tabAccount.%(key)s LIKE '%(txt)s' %(mcond)s""" % {'company': filters['company'], 'key': searchfield,