From 0e7f75f5c0ccbb756373d229874fe729eeee800e Mon Sep 17 00:00:00 2001 From: Jatin3128 <140256508+Jatin3128@users.noreply.github.com> Date: Wed, 26 Nov 2025 17:26:33 +0530 Subject: [PATCH] fix(journal-entry): auto-populate bank account when user selects account (#50744) * fix(journal-entry): auto-populate bank account when user selects account * refactor(journal-entry): simplify get_value call and return None by default --------- Co-authored-by: Jatin3128 --- .../accounts/doctype/journal_entry/journal_entry.js | 11 +++++++++++ .../accounts/doctype/journal_entry/journal_entry.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index c81acb57865..7d179e36a77 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -720,6 +720,8 @@ $.extend(erpnext.journal_entry, { } }, }); + } else { + erpnext.journal_entry.clear_fields(frm, dt, dn); } }, set_amount_on_last_row: function (frm, dt, dn) { @@ -744,4 +746,13 @@ $.extend(erpnext.journal_entry, { } refresh_field("accounts"); }, + clear_fields: function (frm, dt, dn) { + let row = locals[dt][dn]; + + row.party_type = null; + row.party = null; + row.bank_account = null; + + frm.refresh_field("accounts"); + }, }); diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index e4aaf4e7a5a..79cf582974a 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1719,6 +1719,9 @@ def get_account_details_and_party_type(account, date, company, debit=None, credi "party_type": party_type, "account_type": account_details.account_type, "account_currency": account_details.account_currency or company_currency, + "bank_account": ( + frappe.db.get_value("Bank Account", {"account": account, "company": company}) or None + ), # The date used to retreive the exchange rate here is the date passed in # as an argument to this function. It is assumed to be the date on which the balance is sought "exchange_rate": get_exchange_rate(