Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple months in experimental ofx parser #1921

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions packages/loot-core/src/server/accounts/ofx2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,49 @@ function getStmtTrn(data) {
}

function getBankStmtTrn(ofx) {
const msg = ofx?.['BANKMSGSRSV1'];
const stmtTrnRs = msg?.['STMTTRNRS'];
const stmtRs = stmtTrnRs?.['STMTRS'];
const tranList = stmtRs?.['BANKTRANLIST'];
// Could be an array or a single object.
// Somes values could be an array or a single object.
// xml2js serializes single item to an object and multiple to an array.
const stmtTrn = tranList?.['STMTTRN'];

if (!Array.isArray(stmtTrn)) {
return [stmtTrn];
}
return stmtTrn;
const msg = ofx?.['BANKMSGSRSV1'];
const stmtTrnRs = getAsArray(msg?.['STMTTRNRS']);
const result = stmtTrnRs.flatMap(s => {
const stmtRs = s?.['STMTRS'];
const tranList = stmtRs?.['BANKTRANLIST'];
const stmtTrn = tranList?.['STMTTRN'];
return getAsArray(stmtTrn);
});
return result;
}

function getCcStmtTrn(ofx) {
const msg = ofx?.['CREDITCARDMSGSRSV1'];
const stmtTrnRs = msg?.['CCSTMTTRNRS'];
const stmtRs = stmtTrnRs?.['CCSTMTRS'];
const tranList = stmtRs?.['BANKTRANLIST'];
// Could be an array or a single object.
// Some values could be an array or a single object.
// xml2js serializes single item to an object and multiple to an array.
const stmtTrn = tranList?.['STMTTRN'];

if (!Array.isArray(stmtTrn)) {
return [stmtTrn];
}
return stmtTrn;
const msg = ofx?.['CREDITCARDMSGSRSV1'];
const stmtTrnRs = getAsArray(msg?.['CCSTMTTRNRS']);
const result = stmtTrnRs.flatMap(s => {
const stmtRs = s?.['CCSTMTRS'];
const tranList = stmtRs?.['BANKTRANLIST'];
const stmtTrn = tranList?.['STMTTRN'];
return getAsArray(stmtTrn);
});
return result;
}

function getInvStmtTrn(ofx) {
const msg = ofx?.['INVSTMTMSGSRSV1'];
const stmtTrnRs = msg?.['INVSTMTTRNRS'];
const stmtRs = stmtTrnRs?.['INVSTMTRS'];
const tranList = stmtRs?.['INVTRANLIST'];
// Could be an array or a single object.
// Somes values could be an array or a single object.
// xml2js serializes single item to an object and multiple to an array.
const stmtTrn = tranList?.['INVBANKTRAN']?.flatMap(t => t?.['STMTTRN']);
const msg = ofx?.['INVSTMTMSGSRSV1'];
const stmtTrnRs = getAsArray(msg?.['INVSTMTTRNRS']);
const result = stmtTrnRs.flatMap(s => {
const stmtRs = s?.['INVSTMTRS'];
const tranList = stmtRs?.['INVTRANLIST'];
const stmtTrn = tranList?.['INVBANKTRAN']?.flatMap(t => t?.['STMTTRN']);
return getAsArray(stmtTrn);
});
return result;
}

if (!Array.isArray(stmtTrn)) {
return [stmtTrn];
}
return stmtTrn;
function getAsArray(value) {
return Array.isArray(value) ? value : [value];
}

function mapOfxTransaction(stmtTrn): OFXTransaction {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1921.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [joel-jeremy]
---

Experimental ofx parser: Support multiple months in ofx file