Skip to content

fix!: handle multiple companies' bank accounts with one EBICS User - #405

Open
PatrickDEissler wants to merge 4 commits into
version-16-hotfixfrom
issue-404
Open

fix!: handle multiple companies' bank accounts with one EBICS User#405
PatrickDEissler wants to merge 4 commits into
version-16-hotfixfrom
issue-404

Conversation

@PatrickDEissler

Copy link
Copy Markdown
Collaborator

Solves: #404

Further note:
process_camt_document had to be adjusted, because it relied on transactions for one Company per EBICS User.

@PatrickDEissler
PatrickDEissler marked this pull request as draft July 28, 2026 13:08
@PatrickDEissler
PatrickDEissler marked this pull request as ready for review July 28, 2026 13:10
Comment thread banking/ebics/utils.py
@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

This PR is not safe to merge until ambiguous historical IBAN matches stop cross-company routing and existing duplicate records remain administratively manageable.

The importer still continues with the first account when historical duplicates match a statement, while the newly added global validation does not migrate those records and instead prevents either duplicate account from being saved during routine maintenance.

Files Needing Attention: banking/ebics/utils.py and banking/overrides/bank_account.py

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[EBICS User downloads CAMT files] --> B[Read statement IBAN]
  B --> C[Find enabled company Bank Accounts by bank and IBAN]
  C --> D{Number of matches}
  D -->|None| E[Log error and skip statement]
  D -->|One| F[Create transactions for selected account]
  D -->|Multiple historical matches| G[Log ambiguity]
  G --> H[Select first returned account]
  H --> F
Loading
Prompt To Fix All With AI
### Issue 1
banking/overrides/bank_account.py:41-46
**Historical duplicates block account updates**

When an existing Bank Account belongs to a historical duplicate-IBAN pair, this unscoped validation finds the other record and rejects every save, causing routine updates such as assigning a fee account or changing account metadata to fail until administrators manually resolve the historical data.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (2): Last reviewed commit: "fix(Bank Account): avoid duplicate IBANs..." | Re-trigger Greptile

@PatrickDEissler PatrickDEissler changed the title Issue 404 fix!: handle multiple companies' bank accounts with one EBICS User Jul 29, 2026

@barredterra barredterra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think having multiple Bank Accounts with the same IBAN is a configuration error, not a valid scenario. We can validate and log errors, but should not handle it in sync.

IMO the accurate fix should be:

  • replace company field in Ebics User with a data field organization_name (and add a patch) - this is still needed for certificates
  • drop company from get_bank_account() (param and argument)
  • drop company from process_camt_document() and all downstream function calls. No need to fetch it explicitly, it should be set via Bank Transaction's fetch_from.
  • add duplicate IBAN validation to Bank Account
  • in get_bank_account, use get_all, log an error if more than 1 result, return the first result

Comment thread banking/overrides/bank_account.py
@PatrickDEissler

Copy link
Copy Markdown
Collaborator Author

I think having multiple Bank Accounts with the same IBAN is a configuration error, not a valid scenario. We can validate and log errors, but should not handle it in sync.

IMO the accurate fix should be:

  • replace company field in Ebics User with a data field organization_name (and add a patch) - this is still needed for certificates
  • drop company from get_bank_account() (param and argument)
  • drop company from process_camt_document() and all downstream function calls. No need to fetch it explicitly, it should be set via Bank Transaction's fetch_from.
  • add duplicate IBAN validation to Bank Account
  • in get_bank_account, use get_all, log an error if more than 1 result, return the first result

@barredterra
Thanks! I implemented all your suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants