From afd14f6f0efa326d938d6de5762ea9c974a84dfa Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 19 Oct 2015 11:55:28 +0530 Subject: [PATCH] [fix] Allowed accounts with account type='Income Account' for default income account in item --- .../doctype/sales_invoice/sales_invoice.js | 2 +- .../doctype/sales_invoice/sales_invoice.py | 18 -------------- erpnext/controllers/queries.py | 24 +++++++++++++++++++ erpnext/stock/doctype/item/item.js | 6 +---- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 7ff0a364eb..9d620c2692 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -376,7 +376,7 @@ cur_frm.fields_dict['project_name'].get_query = function(doc, cdt, cdn) { // -------------------------------- cur_frm.set_query("income_account", "items", function(doc) { return{ - query: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_income_account", + query: "erpnext.controllers.queries.get_income_account", filters: {'company': doc.company} } }); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 940f754262..d64c6c19bc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -637,24 +637,6 @@ def get_bank_cash_account(mode_of_payment, company): "account": account } - -@frappe.whitelist() -def get_income_account(doctype, txt, searchfield, start, page_len, filters): - from erpnext.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 frappe.db.sql("""select tabAccount.name from `tabAccount` - where (tabAccount.report_type = "Profit and Loss" - or tabAccount.account_type in ("Income Account", "Temporary")) - and tabAccount.is_group=0 - and tabAccount.docstatus!=2 - and tabAccount.company = '%(company)s' - and tabAccount.%(key)s LIKE '%(txt)s' - %(mcond)s""" % {'company': filters['company'], 'key': searchfield, - 'txt': "%%%s%%" % frappe.db.escape(txt), 'mcond':get_match_cond(doctype)}) - @frappe.whitelist() def make_delivery_note(source_name, target_doc=None): def set_missing_values(source, target): diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index a6bfa53e68..e2de6c391e 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -293,3 +293,27 @@ def get_account_list(doctype, txt, searchfield, start, page_len, filters): fields = ["name", "parent_account"], limit_start=start, limit_page_length=page_len, as_list=True) + +@frappe.whitelist() +def get_income_account(doctype, txt, searchfield, start, page_len, filters): + from erpnext.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" + if not filters: filters = {} + + condition = "" + if filters.get("company"): + condition += "and tabAccount.company = %(company)s" + + return frappe.db.sql("""select tabAccount.name from `tabAccount` + where (tabAccount.report_type = "Profit and Loss" + or tabAccount.account_type in ("Income Account", "Temporary")) + and tabAccount.is_group=0 + and tabAccount.`{key}` LIKE %(txt)s + {condition} {match_condition}""" + .format(condition=condition, match_condition=get_match_cond(doctype), key=searchfield), { + 'txt': "%%%s%%" % frappe.db.escape(txt), + 'company': filters.get("company", "") + }) \ No newline at end of file diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 097dd0416d..93f92668eb 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -116,11 +116,7 @@ $.extend(erpnext.item, { // -------------------------------- frm.fields_dict['income_account'].get_query = function(doc) { return { - filters: { - "report_type": "Profit and Loss", - "is_group": 0, - 'account_type': "Income Account" - } + query: "erpnext.controllers.queries.get_income_account" } }