Merge pull request #47972 from frappe/balance

perf: skip fetching balances in payment entry
This commit is contained in:
Ankush Menat
2025-06-10 09:04:31 +05:30
committed by GitHub
2 changed files with 17 additions and 17 deletions

View File

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

View File

@@ -46,7 +46,6 @@ from erpnext.accounts.party import (
from erpnext.accounts.utils import ( from erpnext.accounts.utils import (
cancel_exchange_gain_loss_journal, cancel_exchange_gain_loss_journal,
get_account_currency, get_account_currency,
get_balance_on,
get_outstanding_invoices, get_outstanding_invoices,
) )
from erpnext.controllers.accounts_controller import ( from erpnext.controllers.accounts_controller import (
@@ -2786,7 +2785,6 @@ def get_party_details(company, party_type, party, date, cost_center=None):
party_account = get_party_account(party_type, party, company) party_account = get_party_account(party_type, party, company)
account_currency = get_account_currency(party_account) account_currency = get_account_currency(party_account)
account_balance = get_balance_on(party_account, date, cost_center=cost_center)
_party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name" _party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name"
party_name = frappe.db.get_value(party_type, party, _party_name) party_name = frappe.db.get_value(party_type, party, _party_name)
@@ -2798,7 +2796,6 @@ def get_party_details(company, party_type, party, date, cost_center=None):
"party_account": party_account, "party_account": party_account,
"party_name": party_name, "party_name": party_name,
"party_account_currency": account_currency, "party_account_currency": account_currency,
"account_balance": account_balance,
"party_bank_account": party_bank_account, "party_bank_account": party_bank_account,
"bank_account": bank_account, "bank_account": bank_account,
} }
@@ -2816,12 +2813,9 @@ def get_account_details(account, date, cost_center=None):
if not account_list: if not account_list:
frappe.throw(_("Account: {0} is not permitted under Payment Entry").format(account)) frappe.throw(_("Account: {0} is not permitted under Payment Entry").format(account))
account_balance = get_balance_on(account, date, cost_center=cost_center, ignore_account_permission=True)
return frappe._dict( return frappe._dict(
{ {
"account_currency": get_account_currency(account), "account_currency": get_account_currency(account),
"account_balance": account_balance,
"account_type": frappe.get_cached_value("Account", account, "account_type"), "account_type": frappe.get_cached_value("Account", account, "account_type"),
} }
) )
@@ -3311,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