perf: Skip fetching account balances unless required
This is very expensive operation and not requried when just finding default account and account info.
This commit is contained in:
@@ -1296,7 +1296,9 @@ class JournalEntry(AccountsController):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_default_bank_cash_account(company, account_type=None, mode_of_payment=None, account=None):
|
||||
def get_default_bank_cash_account(
|
||||
company, account_type=None, mode_of_payment=None, account=None, *, fetch_balance=True
|
||||
):
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
|
||||
|
||||
if mode_of_payment:
|
||||
@@ -1330,15 +1332,14 @@ def get_default_bank_cash_account(company, account_type=None, mode_of_payment=No
|
||||
account_details = frappe.get_cached_value(
|
||||
"Account", account, ["account_currency", "account_type"], as_dict=1
|
||||
)
|
||||
|
||||
return frappe._dict(
|
||||
{
|
||||
"account": account,
|
||||
"balance": get_balance_on(account),
|
||||
"account_currency": account_details.account_currency,
|
||||
"account_type": account_details.account_type,
|
||||
}
|
||||
)
|
||||
result = {
|
||||
"account": account,
|
||||
"account_currency": account_details.account_currency,
|
||||
"account_type": account_details.account_type,
|
||||
}
|
||||
if fetch_balance:
|
||||
result["balance"] = get_balance_on(account)
|
||||
return frappe._dict(result)
|
||||
else:
|
||||
return frappe._dict()
|
||||
|
||||
|
||||
@@ -3305,11 +3305,16 @@ def get_bank_cash_account(doc, bank_account):
|
||||
"Bank",
|
||||
mode_of_payment=doc.get("mode_of_payment"),
|
||||
account=bank_account,
|
||||
fetch_balance=False,
|
||||
)
|
||||
|
||||
if not bank:
|
||||
bank = get_default_bank_cash_account(
|
||||
doc.company, "Cash", mode_of_payment=doc.get("mode_of_payment"), account=bank_account
|
||||
doc.company,
|
||||
"Cash",
|
||||
mode_of_payment=doc.get("mode_of_payment"),
|
||||
account=bank_account,
|
||||
fetch_balance=False,
|
||||
)
|
||||
|
||||
return bank
|
||||
|
||||
Reference in New Issue
Block a user