From 7e405e26b62fadc2447d8c99290b3ddd5ed65b42 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 5 Aug 2013 13:00:20 +0530 Subject: [PATCH] [fix] [minor] expense head get_query fixed in purchase invoice --- .../doctype/purchase_invoice/purchase_invoice.js | 15 ++++++--------- .../doctype/purchase_invoice/purchase_invoice.py | 16 +++++++++++++++- accounts/doctype/sales_invoice/sales_invoice.py | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.js b/accounts/doctype/purchase_invoice/purchase_invoice.js index e71a40815f1..b00cfeadc1a 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -172,16 +172,13 @@ return{ } } -cur_frm.fields_dict['entries'].grid.get_field("expense_head").get_query = function(doc) { +cur_frm.set_query("expense_head", "entries", function(doc) { return{ - filters:{ - 'debit_or_credit':'Debit', - 'account_type': 'Expense Account', - 'group_or_ledger': 'Ledger', - 'company': doc.company - } - } -} + query: "accounts.doctype.purchase_invoice.purchase_invoice.get_expense_account", + filters: {'company': doc.company} + } +}); + cur_frm.cscript.expense_head = function(doc, cdt, cdn){ var d = locals[cdt][cdn]; if(d.idx == 1 && d.expense_head){ diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 693ed844f6a..3f94de31884 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -457,4 +457,18 @@ class DocType(BuyingController): "UOM Conversion Detail", {"parent": d.item_code, "uom": d.uom}, "conversion_factor")) or 1 - d.rm_supp_cost = rm_cost * flt(d.qty) * flt(d.conversion_factor) \ No newline at end of file + d.rm_supp_cost = rm_cost * flt(d.qty) * flt(d.conversion_factor) + +@webnotes.whitelist() +def get_expense_account(doctype, txt, searchfield, start, page_len, filters): + from controllers.queries import get_match_cond + + return webnotes.conn.sql("""select tabAccount.name from `tabAccount` + where (tabAccount.debit_or_credit="Debit" + or tabAccount.account_type = "Expense Account") + and tabAccount.group_or_ledger="Ledger" + 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%%" % txt, 'mcond':get_match_cond(doctype, searchfield)}) \ No newline at end of file diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index bf5e201f6b3..adadcc81d17 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -979,6 +979,7 @@ def get_bank_cash_account(mode_of_payment): "cash_bank_account": val } +@webnotes.whitelist() def get_income_account(doctype, txt, searchfield, start, page_len, filters): from controllers.queries import get_match_cond