-
-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pending transaction amount sign and payee name for National Bank …
…of Greece import (#448) * fixed pending transaction amount sign and payeeName for NBG bank import * added release note --------- Co-authored-by: Stefanos Chatzimichelakis <[email protected]>
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import Fallback from './integration-bank.js'; | ||
|
||
import { printIban, amountToInteger } from '../utils.js'; | ||
import { formatPayeeName } from '../../util/payee-name.js'; | ||
|
||
/** @type {import('./bank.interface.js').IBank} */ | ||
export default { | ||
...Fallback, | ||
|
||
institutionIds: ['NBG_ETHNGRAAXXX'], | ||
|
||
accessValidForDays: 90, | ||
|
||
normalizeAccount(account) { | ||
return { | ||
account_id: account.id, | ||
institution: account.institution, | ||
mask: account.iban.slice(-4), | ||
iban: account.iban, | ||
name: [account.name, printIban(account)].join(' '), | ||
official_name: account.product, | ||
type: 'checking', | ||
}; | ||
}, | ||
|
||
/** | ||
* Fixes for the pending transactions: | ||
* - Corrects amount to negative (nbg erroneously omits the minus sign in pending transactions) | ||
* - Removes prefix 'ΑΓΟΡΑ' from remittance information to align with the booked transaction (necessary for fuzzy matching to work) | ||
*/ | ||
normalizeTransaction(transaction, _booked) { | ||
if ( | ||
!transaction.transactionId && | ||
transaction.remittanceInformationUnstructured.startsWith('ΑΓΟΡΑ ') | ||
) { | ||
transaction = { | ||
...transaction, | ||
transactionAmount: { | ||
amount: '-' + transaction.transactionAmount.amount, | ||
currency: transaction.transactionAmount.currency, | ||
}, | ||
remittanceInformationUnstructured: | ||
transaction.remittanceInformationUnstructured.substring(6), | ||
}; | ||
} | ||
|
||
return { | ||
...transaction, | ||
payeeName: formatPayeeName(transaction), | ||
date: transaction.bookingDate || transaction.valueDate, | ||
}; | ||
}, | ||
|
||
/** | ||
* For NBG_ETHNGRAAXXX we don't know what balance was | ||
* after each transaction so we have to calculate it by getting | ||
* current balance from the account and subtract all the transactions | ||
* | ||
* As a current balance we use `interimBooked` balance type because | ||
* it includes transaction placed during current day | ||
*/ | ||
calculateStartingBalance(sortedTransactions = [], balances = []) { | ||
const currentBalance = balances.find( | ||
(balance) => 'interimAvailable' === balance.balanceType, | ||
); | ||
|
||
return sortedTransactions.reduce((total, trans) => { | ||
return total - amountToInteger(trans.transactionAmount.amount); | ||
}, amountToInteger(currentBalance.balanceAmount.amount)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import NbgEthngraaxxx from '../nbg_ethngraaxxx.js'; | ||
|
||
describe('NbgEthngraaxxx', () => { | ||
describe('#normalizeTransaction', () => { | ||
it('provides correct amount in pending transaction and removes payee prefix', () => { | ||
const transaction = { | ||
bookingDate: '2024-09-03', | ||
date: '2024-09-03', | ||
remittanceInformationUnstructured: 'ΑΓΟΡΑ testingson', | ||
transactionAmount: { | ||
amount: '100.00', | ||
currency: 'EUR', | ||
}, | ||
valueDate: '2024-09-03', | ||
}; | ||
|
||
const normalizedTransaction = NbgEthngraaxxx.normalizeTransaction( | ||
transaction, | ||
false, | ||
); | ||
|
||
expect(normalizedTransaction.transactionAmount.amount).toEqual('-100.00'); | ||
expect(normalizedTransaction.payeeName).toEqual('Testingson'); | ||
}); | ||
}); | ||
|
||
it('provides correct amount and payee in booked transaction', () => { | ||
const transaction = { | ||
transactionId: 'O244015L68IK', | ||
bookingDate: '2024-09-03', | ||
date: '2024-09-03', | ||
remittanceInformationUnstructured: 'testingson', | ||
transactionAmount: { | ||
amount: '-100.00', | ||
currency: 'EUR', | ||
}, | ||
valueDate: '2024-09-03', | ||
}; | ||
|
||
const normalizedTransaction = NbgEthngraaxxx.normalizeTransaction( | ||
transaction, | ||
true, | ||
); | ||
|
||
expect(normalizedTransaction.transactionAmount.amount).toEqual('-100.00'); | ||
expect(normalizedTransaction.payeeName).toEqual('Testingson'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Bugfix | ||
authors: [mezger6] | ||
--- | ||
|
||
Fix pending purchases amount sign and payee name for National Bank of Greece import |