Skip to content
Snippets Groups Projects
Unverified Commit 0af7e3a0 authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:bug: (ynab4) transaction cleared state in imports (#490)

Closes #399
parent d36417e4
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,7 @@ function sortByKey(arr, key) { ...@@ -41,7 +41,7 @@ function sortByKey(arr, key) {
} }
function groupBy(arr, keyName) { function groupBy(arr, keyName) {
return arr.reduce(function(obj, item) { return arr.reduce(function (obj, item) {
var key = item[keyName]; var key = item[keyName];
if (!obj.hasOwnProperty(key)) { if (!obj.hasOwnProperty(key)) {
obj[key] = []; obj[key] = [];
...@@ -208,20 +208,18 @@ async function importTransactions(data, entityIdMap) { ...@@ -208,20 +208,18 @@ async function importTransactions(data, entityIdMap) {
let id = entityIdMap.get(transaction.entityId); let id = entityIdMap.get(transaction.entityId);
function transferProperties(t) { function transferProperties(t) {
let transferId = let transferId = entityIdMap.get(t.transferTransactionId) || null;
entityIdMap.get(t.transferTransactionId) || null;
let payee = null; let payee = null;
if (transferId) { if (transferId) {
payee = payees.find( payee = payees.find(
p => p => p.transfer_acct === entityIdMap.get(t.targetAccountId)
p.transfer_acct === entityIdMap.get(t.targetAccountId)
).id; ).id;
} else { } else {
payee = entityIdMap.get(t.payeeId); payee = entityIdMap.get(t.payeeId);
} }
return { transfer_id: transferId, payee } return { transfer_id: transferId, payee };
} }
let newTransaction = { let newTransaction = {
...@@ -232,7 +230,8 @@ async function importTransactions(data, entityIdMap) { ...@@ -232,7 +230,8 @@ async function importTransactions(data, entityIdMap) {
: getCategory(transaction.categoryId), : getCategory(transaction.categoryId),
date: transaction.date, date: transaction.date,
notes: transaction.memo || null, notes: transaction.memo || null,
...transferProperties(transaction), cleared: transaction.cleared === 'Cleared',
...transferProperties(transaction)
}; };
newTransaction.subtransactions = newTransaction.subtransactions =
...@@ -242,8 +241,8 @@ async function importTransactions(data, entityIdMap) { ...@@ -242,8 +241,8 @@ async function importTransactions(data, entityIdMap) {
amount: amountToInteger(t.amount), amount: amountToInteger(t.amount),
category: getCategory(t.categoryId), category: getCategory(t.categoryId),
notes: t.memo || null, notes: t.memo || null,
...transferProperties(t), ...transferProperties(t)
}; };
}); });
return newTransaction; return newTransaction;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment