mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-30 03:23:51 -05:00
Enrich pending transaction creditor info for SWEDBANK_HABALV22 (#497)
This commit is contained in:
@@ -14,17 +14,36 @@ export default {
|
|||||||
* The actual transaction date for card transactions is only available in the remittanceInformationUnstructured field when the transaction is booked.
|
* The actual transaction date for card transactions is only available in the remittanceInformationUnstructured field when the transaction is booked.
|
||||||
*/
|
*/
|
||||||
normalizeTransaction(transaction, booked) {
|
normalizeTransaction(transaction, booked) {
|
||||||
const dateMatch = transaction.remittanceInformationUnstructured?.match(
|
const isCardTransaction =
|
||||||
/PIRKUMS [\d*]+ (\d{2}.\d{2}.\d{4})/,
|
transaction.remittanceInformationUnstructured?.startsWith('PIRKUMS');
|
||||||
);
|
|
||||||
|
|
||||||
if (dateMatch) {
|
if (isCardTransaction) {
|
||||||
const extractedDate = d.parse(dateMatch[1], 'dd.MM.yyyy', new Date());
|
if (!booked && !transaction.creditorName) {
|
||||||
|
const creditorNameMatch =
|
||||||
|
transaction.remittanceInformationUnstructured?.match(
|
||||||
|
/PIRKUMS [\d*]+ \d{2}\.\d{2}\.\d{2} \d{2}:\d{2} [\d.]+ \w{3} \(\d+\) (.+)/,
|
||||||
|
);
|
||||||
|
|
||||||
return Fallback.normalizeTransaction(
|
if (creditorNameMatch) {
|
||||||
{ ...transaction, bookingDate: d.format(extractedDate, 'yyyy-MM-dd') },
|
transaction = {
|
||||||
booked,
|
...transaction,
|
||||||
|
creditorName: creditorNameMatch[1],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateMatch = transaction.remittanceInformationUnstructured?.match(
|
||||||
|
/PIRKUMS [\d*]+ (\d{2}\.\d{2}\.\d{4})/,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (dateMatch) {
|
||||||
|
const extractedDate = d.parse(dateMatch[1], 'dd.MM.yyyy', new Date());
|
||||||
|
|
||||||
|
transaction = {
|
||||||
|
...transaction,
|
||||||
|
bookingDate: d.format(extractedDate, 'yyyy-MM-dd'),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Fallback.normalizeTransaction(transaction, booked);
|
return Fallback.normalizeTransaction(transaction, booked);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import SwedbankHabaLV22 from '../swedbank-habalv22.js';
|
import SwedbankHabaLV22 from '../swedbank-habalv22.js';
|
||||||
|
|
||||||
describe('#normalizeTransaction', () => {
|
describe('#normalizeTransaction', () => {
|
||||||
const cardTransaction = {
|
const bookedCardTransaction = {
|
||||||
transactionId: '2024102900000000-1',
|
transactionId: '2024102900000000-1',
|
||||||
bookingDate: '2024-10-29',
|
bookingDate: '2024-10-29',
|
||||||
valueDate: '2024-10-29',
|
valueDate: '2024-10-29',
|
||||||
@@ -18,11 +18,12 @@ describe('#normalizeTransaction', () => {
|
|||||||
|
|
||||||
it('extracts card transaction date', () => {
|
it('extracts card transaction date', () => {
|
||||||
expect(
|
expect(
|
||||||
SwedbankHabaLV22.normalizeTransaction(cardTransaction, true).bookingDate,
|
SwedbankHabaLV22.normalizeTransaction(bookedCardTransaction, true)
|
||||||
|
.bookingDate,
|
||||||
).toEqual('2024-10-28');
|
).toEqual('2024-10-28');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
SwedbankHabaLV22.normalizeTransaction(cardTransaction, true).date,
|
SwedbankHabaLV22.normalizeTransaction(bookedCardTransaction, true).date,
|
||||||
).toEqual('2024-10-28');
|
).toEqual('2024-10-28');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ describe('#normalizeTransaction', () => {
|
|||||||
['null value', null],
|
['null value', null],
|
||||||
])('normalizes non-card transaction with %s', (_, remittanceInfo) => {
|
])('normalizes non-card transaction with %s', (_, remittanceInfo) => {
|
||||||
const transaction = {
|
const transaction = {
|
||||||
...cardTransaction,
|
...bookedCardTransaction,
|
||||||
remittanceInformationUnstructured: remittanceInfo,
|
remittanceInformationUnstructured: remittanceInfo,
|
||||||
};
|
};
|
||||||
const normalized = SwedbankHabaLV22.normalizeTransaction(transaction, true);
|
const normalized = SwedbankHabaLV22.normalizeTransaction(transaction, true);
|
||||||
@@ -40,4 +41,22 @@ describe('#normalizeTransaction', () => {
|
|||||||
expect(normalized.bookingDate).toEqual('2024-10-29');
|
expect(normalized.bookingDate).toEqual('2024-10-29');
|
||||||
expect(normalized.date).toEqual('2024-10-29');
|
expect(normalized.date).toEqual('2024-10-29');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pendingCardTransaction = {
|
||||||
|
transactionId: '2024102900000000-1',
|
||||||
|
valueDate: '2024-10-29',
|
||||||
|
transactionAmount: {
|
||||||
|
amount: '-22.99',
|
||||||
|
currency: 'EUR',
|
||||||
|
},
|
||||||
|
remittanceInformationUnstructured:
|
||||||
|
'PIRKUMS 424242******4242 28.10.24 13:37 22.99 EUR (111111) SOME CREDITOR NAME',
|
||||||
|
};
|
||||||
|
|
||||||
|
it('extracts pending card transaction creditor name', () => {
|
||||||
|
expect(
|
||||||
|
SwedbankHabaLV22.normalizeTransaction(pendingCardTransaction, false)
|
||||||
|
.creditorName,
|
||||||
|
).toEqual('SOME CREDITOR NAME');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
6
upcoming-release-notes/497.md
Normal file
6
upcoming-release-notes/497.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
category: Enhancements
|
||||||
|
authors: [dmednis]
|
||||||
|
---
|
||||||
|
|
||||||
|
Improve support for "SWEDBANK_HABALV22" transaction date & enrich creditor name for pending transactions
|
||||||
Reference in New Issue
Block a user