diff --git a/packages/loot-core/src/mocks/files/data-multi-decimal.ofx b/packages/loot-core/src/mocks/files/data-multi-decimal.ofx new file mode 100644 index 00000000000..ea4901d3681 --- /dev/null +++ b/packages/loot-core/src/mocks/files/data-multi-decimal.ofx @@ -0,0 +1,64 @@ +OFXHEADER:100 +DATA:OFXSGML +VERSION:102 +SECURITY:NONE +ENCODING:USASCII +CHARSET:1252 +COMPRESSION:NONE +OLDFILEUID:NONE +NEWFILEUID:NONE + + + + + + 0 + INFO + + 20190124212851.000[0:UTC] + ENG + 20190124212851.000[0:UTC] + + Bank of America + 5959 + + 6526 + jlongster03 + + + + + 0 + + 0 + INFO + + + USD + + 012345678 + 123456789123 + CHECKING + + + 20190119120000 + 20190124120000 + + DEBIT + 20190123120000 + -30.000 + 00092990122-30.00019012312798.01 + PATIENT FIRST TOKEN 01/22 PURCHA + + + DEBIT + 20190123120000 + -3.77000 + 00092990121-3.77019012312828.01 + STARBUCKS STORE 07604 01/21 PURC + + + + + + diff --git a/packages/loot-core/src/server/accounts/parse-file.test.ts b/packages/loot-core/src/server/accounts/parse-file.test.ts index edd472d2ab0..345d098027e 100644 --- a/packages/loot-core/src/server/accounts/parse-file.test.ts +++ b/packages/loot-core/src/server/accounts/parse-file.test.ts @@ -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' }); diff --git a/packages/loot-core/src/server/accounts/parse-file.ts b/packages/loot-core/src/server/accounts/parse-file.ts index ef7df445177..03c34f076b5 100644 --- a/packages/loot-core/src/server/accounts/parse-file.ts +++ b/packages/loot-core/src/server/accounts/parse-file.ts @@ -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), diff --git a/upcoming-release-notes/2421.md b/upcoming-release-notes/2421.md new file mode 100644 index 00000000000..cf6ee5c5fb1 --- /dev/null +++ b/upcoming-release-notes/2421.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [keriati] +--- + +Fix OFX import amount when more than 2 decimal places are provided