Skip to content

Conversation

@Abdeali099
Copy link
Contributor

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Nov 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

📝 Walkthrough

Walkthrough

This pull request adds automatic bank account selection to the Payment Entry form. It introduces a new helper method set_company_bank_account() that queries and populates the bank_account field based on the company and the selected paid_from or paid_to account. The method is triggered when those fields change and includes a guard flag to prevent recursive updates during bank account synchronization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Guard mechanism: Verify that the frm.set_company_bank_account_based_on_coa flag correctly prevents infinite recursion between the paid_from/paid_to handlers and the bank_account handler.
  • Query logic: Ensure the Bank Account lookup by company and account correctly handles both Pay and Receive payment types and returns the expected result.
  • Field handler integration: Confirm that calling set_company_bank_account() at the start of paid_from and paid_to handlers doesn't interfere with existing logic in those methods.

Possibly related PRs

  • #49735: Modifies the same paid_from and paid_to handlers in payment_entry.js; coordinate changes to avoid conflicts in these overlapping touch points.

Suggested labels

backport version-15-hotfix

Suggested reviewers

  • ruthra-kumar

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description references the linked issue (#36256) and indicates a backport plan, directly relating to the changeset.
Linked Issues check ✅ Passed The implementation adds auto-selection of Bank Account when COA bank account is selected in Payment Entry, directly addressing issue #36256 requirements.
Out of Scope Changes check ✅ Passed All changes are scoped to Payment Entry's bank account auto-selection behavior as specified in the linked issue.
Title check ✅ Passed The title clearly and specifically describes the main change: adding automatic fetching of company bank account when paid_from/paid_to fields change in Payment Entry.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 689eee7 and 41cbf9e.

📒 Files selected for processing (2)
  • erpnext/accounts/doctype/bank_account/bank_account.py (1 hunks)
  • erpnext/accounts/doctype/payment_entry/payment_entry.js (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
erpnext/accounts/doctype/bank_account/bank_account.py (1)
erpnext/accounts/doctype/payment_entry/payment_entry.js (2)
  • frappe (1700-1700)
  • account (1282-1284)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Python Unit Tests (3)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Python Unit Tests (4)
  • GitHub Check: Patch Test
  • GitHub Check: Summary
🔇 Additional comments (5)
erpnext/accounts/doctype/bank_account/bank_account.py (1)

120-124: LGTM with a minor observation.

The function correctly queries for a Bank Account using cached values and enforces permissions. The implicit return of the document name (when frappe.get_cached_value is called without explicit field names) is appropriate for the use case.

One note: if multiple Bank Accounts somehow share the same company and account (which validate_account should prevent), the function returns the first match without explicit ordering. This should be fine given the existing validation.

erpnext/accounts/doctype/payment_entry/payment_entry.js (4)

577-593: LGTM! Good placement of the bank account lookup.

The call to set_company_bank_account at the start of the paid_from handler ensures that the company bank account is populated whenever the paid-from account changes, which aligns with the PR objectives.


595-618: LGTM! Consistent with the paid_from handler.

The symmetrical implementation in the paid_to handler ensures bank account auto-selection works for both payment types (Pay and Receive).


1380-1380: Consider the implications of skipping when bank_account is already set.

The early return when bank_account is already populated means that changing the paid_from or paid_to account won't update the bank account if one is already selected. This could lead to a mismatch where the bank account no longer corresponds to the selected COA account.

Please verify whether this is the intended behavior. If users should be able to have the bank account auto-update when they change the account, this check should be removed or modified to allow updates when the account field changes.


1382-1393: LGTM! Clean API integration.

The API call properly passes the required parameters and only updates the bank_account field when a valid result is returned. The implicit handling of null/undefined results (when no matching bank account exists) is appropriate.

@Abdeali099 Abdeali099 force-pushed the set-company-bank-account branch from 41cbf9e to 9d9fa66 Compare November 4, 2025 07:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41cbf9e and 9d9fa66.

📒 Files selected for processing (2)
  • erpnext/accounts/doctype/bank_account/bank_account.py (1 hunks)
  • erpnext/accounts/doctype/payment_entry/payment_entry.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • erpnext/accounts/doctype/bank_account/bank_account.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Python Unit Tests (4)
  • GitHub Check: Python Unit Tests (3)
  • GitHub Check: Python Unit Tests (1)
  • GitHub Check: Python Unit Tests (2)
  • GitHub Check: Patch Test
  • GitHub Check: Summary

@Abdeali099 Abdeali099 force-pushed the set-company-bank-account branch from 9d9fa66 to e76cafc Compare November 4, 2025 10:56
@Abdeali099 Abdeali099 force-pushed the set-company-bank-account branch from e76cafc to 4901dc2 Compare November 4, 2025 10:58
@diptanilsaha diptanilsaha self-assigned this Nov 11, 2025
@diptanilsaha diptanilsaha changed the title fix: on changes of paid from/to account fetch company bank account fix(payment entry): on changes of paid from/to account fetch company bank account Nov 12, 2025
@diptanilsaha diptanilsaha merged commit 51d583b into frappe:develop Nov 12, 2025
12 checks passed
diptanilsaha added a commit that referenced this pull request Nov 12, 2025
…-50323

fix(payment entry): on changes of paid from/to account fetch company bank account (backport #50323)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport version-15-hotfix needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto selection of Bank Account on selection of COA account of bank in JE and Payment Entry

2 participants