Skip to content

Commit

Permalink
Support NYNAB import of transactions that contain subtransactions tha…
Browse files Browse the repository at this point in the history
…t are transfers

A subtransaction is considered a transfer from ynab
if
- the transfer_account_id is set
- the category_id is null (transfers dont have categories)
  • Loading branch information
Marethyu1 committed Oct 29, 2023
1 parent e12793e commit ad45202
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
43 changes: 42 additions & 1 deletion packages/desktop-client/e2e/data/ynab5-demo-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -1671,9 +1671,50 @@
"import_payee_name_original": null,
"debt_transaction_type": null,
"deleted": false
},
{
"id": "213526fc-ba49-4790-8a96-cc2a50182728",
"date": "2023-09-04",
"amount": -100000,
"memo": "Test transaction",
"cleared": "cleared",
"approved": true,
"flag_color": null,
"account_id": "bc1d862f-bab0-41c3-bd1e-6cee8c688e32",
"payee_id": "2a20470a-634f-4efa-a7f6-f1c0b0bdda41",
"category_id": "36120d44-6c61-4402-985a-891a8d267858",
"transfer_account_id": null,
"transfer_transaction_id": null,
"matched_transaction_id": null,
"import_id": null,
"import_payee_name": null,
"import_payee_name_original": null,
"debt_transaction_type": null,
"deleted": false
}
],
"subtransactions": [
{
"id": "d8ec8c84-5033-4f7e-8485-66bfe19a70d6",
"transaction_id": "213526fc-ba49-4790-8a96-cc2a50182728",
"amount": -50000,
"memo": "split part a",
"payee_id": "2a20470a-634f-4efa-a7f6-f1c0b0bdda41",
"category_id": "36120d44-6c61-4402-985a-891a8d267858",
"transfer_account_id": null,
"deleted": false
},
{
"id": "870d8780-79cf-4197-a341-47d24b2b5a59",
"transaction_id": "213526fc-ba49-4790-8a96-cc2a50182728",
"amount": -50000,
"memo": "split part b",
"payee_id": "2a20470a-634f-4efa-a7f6-f1c0b0bdda41",
"category_id": null,
"transfer_account_id": "125f339b-2a63-481e-84c0-f04d898905d2",
"deleted": false
}
],
"subtransactions": [],
"scheduled_transactions": [],
"scheduled_subtransactions": []
},
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/server/importers/ynab5-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export namespace YNAB5 {
category_id: string;
memo: string;
amount: number;
transfer_account_id: string;
}

interface Month {
Expand Down
11 changes: 11 additions & 0 deletions packages/loot-core/src/server/importers/ynab5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,22 @@ async function importTransactions(
entityIdMap.get(transaction.transfer_transaction_id) || null,
subtransactions: subtransactions
? subtransactions.map(subtrans => {

Check warning on line 181 in packages/loot-core/src/server/importers/ynab5.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
let payee = null;
if (subtrans.transfer_account_id){

Check warning on line 183 in packages/loot-core/src/server/importers/ynab5.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
payee = payees.find(
p =>
p.transfer_acct ===
entityIdMap.get(subtrans.transfer_account_id),
).id;
}

return {
id: entityIdMap.get(subtrans.id),
amount: amountFromYnab(subtrans.amount),
category: entityIdMap.get(subtrans.category_id) || null,
notes: subtrans.memo,
payee: payee

Check warning on line 196 in packages/loot-core/src/server/importers/ynab5.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
};
})
: null,
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1835.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: BugFix
authors: [Marethyu1]
---

UPDATES NYNAB import to support importing transactions that contain sub transactions that are account transfers

0 comments on commit ad45202

Please sign in to comment.