Skip to content

Commit

Permalink
fix ofx amount parsing for longer decimal places (actualbudget#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
keriati authored Mar 6, 2024
1 parent 3a07ede commit 25b7a66
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
64 changes: 64 additions & 0 deletions packages/loot-core/src/mocks/files/data-multi-decimal.ofx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE

<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<DTSERVER>20190124212851.000[0:UTC]
<LANGUAGE>ENG
<DTACCTUP>20190124212851.000[0:UTC]
<FI>
<ORG>Bank of America
<FID>5959
</FI>
<INTU.BID>6526
<INTU.USERID>jlongster03
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>0
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<STMTRS>
<CURDEF>USD
<BANKACCTFROM>
<BANKID>012345678
<ACCTID>123456789123
<ACCTTYPE>CHECKING
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20190119120000
<DTEND>20190124120000
<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20190123120000
<TRNAMT>-30.000
<FITID>00092990122-30.00019012312798.01
<NAME>PATIENT FIRST TOKEN 01/22 PURCHA
</STMTTRN>
<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20190123120000
<TRNAMT>-3.77000
<FITID>00092990121-3.77019012312828.01
<NAME>STARBUCKS STORE 07604 01/21 PURC
</STMTTRN>
</BANKTRANLIST>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>
12 changes: 12 additions & 0 deletions packages/loot-core/src/server/accounts/parse-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ describe('File import', () => {
expect(await getTransactions('one')).toMatchSnapshot();
}, 45000);

test('ofx import works with multiple decimals in amount', async () => {
const ofxFile = __dirname + '/../../mocks/files/data-multi-decimal.ofx';

const { transactions } = (await parseFile(ofxFile)) as {
transactions: { amount: number }[];
};

expect(transactions).toHaveLength(2);
expect(transactions[0].amount).toBe(-30.0);
expect(transactions[1].amount).toBe(-3.77);
}, 45000);

test('ofx import works (credit card)', async () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/accounts/parse-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async function parseOFX(
errors,
transactions: data.transactions.map(trans => {
return {
amount: trans.amount,
amount: Number(trans.amount),
imported_id: trans.fitId,
date: trans.date,
payee_name: trans.name || (useMemoFallback ? trans.memo : null),
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2421.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [keriati]
---

Fix OFX import amount when more than 2 decimal places are provided

0 comments on commit 25b7a66

Please sign in to comment.