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()
|
@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
|
from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
|
||||||
|
|
||||||
if mode_of_payment:
|
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_details = frappe.get_cached_value(
|
||||||
"Account", account, ["account_currency", "account_type"], as_dict=1
|
"Account", account, ["account_currency", "account_type"], as_dict=1
|
||||||
)
|
)
|
||||||
|
result = {
|
||||||
return frappe._dict(
|
"account": account,
|
||||||
{
|
"account_currency": account_details.account_currency,
|
||||||
"account": account,
|
"account_type": account_details.account_type,
|
||||||
"balance": get_balance_on(account),
|
}
|
||||||
"account_currency": account_details.account_currency,
|
if fetch_balance:
|
||||||
"account_type": account_details.account_type,
|
result["balance"] = get_balance_on(account)
|
||||||
}
|
return frappe._dict(result)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return frappe._dict()
|
return frappe._dict()
|
||||||
|
|
||||||
|
|||||||
@@ -3305,11 +3305,16 @@ def get_bank_cash_account(doc, bank_account):
|
|||||||
"Bank",
|
"Bank",
|
||||||
mode_of_payment=doc.get("mode_of_payment"),
|
mode_of_payment=doc.get("mode_of_payment"),
|
||||||
account=bank_account,
|
account=bank_account,
|
||||||
|
fetch_balance=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not bank:
|
if not bank:
|
||||||
bank = get_default_bank_cash_account(
|
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
|
return bank
|
||||||
|
|||||||
Reference in New Issue
Block a user