Merge pull request #4190 from nabinhait/income_expense_account_query

[fix] Allowed accounts with account type='Income Account' for default income account in item
This commit is contained in:
Anand Doshi 2015-10-19 15:43:32 +05:30
commit 9dad86c189
4 changed files with 26 additions and 24 deletions

View File

@ -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}
}
});

View File

@ -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):

View File

@ -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", "")
})

View File

@ -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"
}
}