Skip to content

A local-first personal finance app

[AI] Fix Enable Banking counterparty selection by payment direction (#9204)

ANURAG VERMAaf7c06fcb3b7
diff --git a/packages/sync-server/src/app-enablebanking/services/enablebanking-service.ts b/packages/sync-server/src/app-enablebanking/services/enablebanking-service.ts
index c5c722969a..46bac59594 100644
--- a/packages/sync-server/src/app-enablebanking/services/enablebanking-service.ts
+++ b/packages/sync-server/src/app-enablebanking/services/enablebanking-service.ts
@@ -19,8 +19,8 @@ export type EnableBankingTransaction = {
entry_reference?: string;
transaction_id?: string;
transaction_amount: { currency: string; amount: string };
- creditor?: { name?: string };
- debtor?: { name?: string };
+ creditor?: { name?: string | null } | null;
+ debtor?: { name?: string | null } | null;
credit_debit_indicator?: 'CRDT' | 'DBIT';
status?: 'BOOK' | 'PDNG';
booking_date?: string;
@@ -215,27 +215,21 @@ export function normalizeTransaction(
const valueDate = tx.value_date;
let payeeName = '';
- if (tx.credit_debit_indicator === 'CRDT' && tx.debtor?.name) {
- payeeName = tx.debtor.name;
- } else if (tx.credit_debit_indicator === 'DBIT' && tx.creditor?.name) {
- payeeName = tx.creditor.name;
- } else if (tx.creditor?.name) {
- payeeName = tx.creditor.name;
- } else if (tx.debtor?.name) {
- payeeName = tx.debtor.name;
- } else if (
- tx.remittance_information &&
- tx.remittance_information.length > 0
- ) {
- const cleanedFallback = cleanRemittanceArray(tx.remittance_information);
- if (cleanedFallback.length > 0) {
- payeeName = cleanedFallback[0];
- }
+ // With a known direction, the other party is the account holder.
+ if (tx.credit_debit_indicator === 'CRDT') {
+ payeeName = tx.debtor?.name || '';
+ } else if (tx.credit_debit_indicator === 'DBIT') {
+ payeeName = tx.creditor?.name || '';
+ } else {
+ payeeName = tx.creditor?.name || tx.debtor?.name || '';
}
const cleanedAll = tx.remittance_information
? cleanRemittanceArray(tx.remittance_information)
: [];
+ if (!payeeName) {
+ payeeName = cleanedAll[0] || '';
+ }
const remittanceInformationUnstructured =
cleanedAll.length > 0 ? cleanedAll.join(' ') : undefined;
diff --git a/packages/sync-server/src/app-enablebanking/services/tests/normalization.spec.ts b/packages/sync-server/src/app-enablebanking/services/tests/normalization.spec.ts
index 7c15c64dbd..de1bb380cf 100644
--- a/packages/sync-server/src/app-enablebanking/services/tests/normalization.spec.ts
+++ b/packages/sync-server/src/app-enablebanking/services/tests/normalization.spec.ts
@@ -43,6 +43,101 @@ describe('normalizeTransaction', () => {
expect(result.transactionAmount.amount).toBe('-25.99');
});
+ // GH #9165: a missing counterparty must not select the account holder.
+ it('should not use the account holder as payee for DBIT when creditor is missing', () => {
+ const result = normalizeTransaction({
+ ...mockDebitTransaction,
+ creditor: null,
+ debtor: { name: 'Account Holder' },
+ transaction_amount: { currency: 'EUR', amount: '-21.58' },
+ booking_date: '2026-10-02',
+ remittance_information: ['Card purchase at Example Merchant'],
+ });
+
+ expect(result).toMatchObject({
+ transactionAmount: { amount: '-21.58', currency: 'EUR' },
+ bookingDate: '2026-10-02',
+ notes: 'Card purchase at Example Merchant',
+ });
+ expect(result.payeeName).toBe('Card purchase at Example Merchant');
+ });
+
+ it('should not use the account holder as payee for CRDT when debtor is missing', () => {
+ const result = normalizeTransaction({
+ ...mockCreditTransaction,
+ debtor: undefined,
+ creditor: { name: 'Account Holder' },
+ });
+
+ expect(result.payeeName).toBe('Monthly salary');
+ });
+
+ it.each(['DBIT', 'CRDT'] as const)(
+ 'should use cleaned remittance for %s with an empty counterparty name',
+ credit_debit_indicator => {
+ const result = normalizeTransaction({
+ ...mockDebitTransaction,
+ credit_debit_indicator,
+ creditor: {
+ name: credit_debit_indicator === 'DBIT' ? '' : 'Account Holder',
+ },
+ debtor: {
+ name: credit_debit_indicator === 'CRDT' ? null : 'Account Holder',
+ },
+ remittance_information: [
+ 'EREF+',
+ 'SVWZ+Merchant description',
+ 'Extra notes',
+ ],
+ });
+
+ expect(result.payeeName).toBe('Merchant description');
+ expect(result.notes).toBe('Merchant description Extra notes');
+ },
+ );
+
+ it.each(['DBIT', 'CRDT'] as const)(
+ 'should leave payee empty for %s when counterparty and usable remittance are absent',
+ credit_debit_indicator => {
+ const result = normalizeTransaction({
+ ...mockDebitTransaction,
+ credit_debit_indicator,
+ creditor:
+ credit_debit_indicator === 'DBIT'
+ ? undefined
+ : { name: 'Account Holder' },
+ debtor:
+ credit_debit_indicator === 'CRDT' ? null : { name: 'Account Holder' },
+ remittance_information: ['EREF+', ' '],
+ });
+
+ expect(result.payeeName).toBe('');
+ expect(result.notes).toBeUndefined();
+ },
+ );
+
+ it.each([
+ {
+ creditor: { name: 'Creditor' },
+ debtor: { name: 'Debtor' },
+ expected: 'Creditor',
+ },
+ { creditor: null, debtor: { name: 'Debtor' }, expected: 'Debtor' },
+ ])(
+ 'should preserve party fallback without a direction: $expected',
+ ({ creditor, debtor, expected }) => {
+ const result = normalizeTransaction({
+ ...mockDebitTransaction,
+ credit_debit_indicator: undefined,
+ creditor,
+ debtor,
+ });
+
+ expect(result.payeeName).toBe(expected);
+ expect(result.transactionAmount.amount).toBe('-25.99');
+ },
+ );
+
it('should mark PDNG transactions as not booked', () => {
const result = normalizeTransaction(mockPendingTransaction);
expect(result.booked).toBe(false);
diff --git a/upcoming-release-notes/fix-enablebanking-counterparty.md b/upcoming-release-notes/fix-enablebanking-counterparty.md
new file mode 100644
index 0000000000..8af2549e9d
--- /dev/null
+++ b/upcoming-release-notes/fix-enablebanking-counterparty.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [anuragverma57]
+---
+
+Fix Enable Banking imports selecting the account holder as the payee when the counterparty name is missing, using the transaction description as a fallback instead.