A local-first personal finance app
Fetch GoCardless transactions from the last 90 days or since first transaction (#1484)
Johannes Löthberg6912c082b184
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.tsindex ef41374360..fc45e1f8db 100644--- a/packages/loot-core/src/server/accounts/sync.ts+++ b/packages/loot-core/src/server/accounts/sync.ts@@ -752,29 +752,27 @@ export async function syncGoCardlessAccount('SELECT date FROM v_transactions WHERE account = ? ORDER BY date ASC LIMIT 1',[id],);- const startingDate = db.fromDateRepr(startingTransaction.date);- // assert(startingTransaction)+ const startingDate = monthUtils.parseDate(+ db.fromDateRepr(startingTransaction.date),+ );- // Get all transactions since the latest transaction, plus any 5- // days before the latest transaction. This gives us a chance to- // resolve any transactions that were entered manually.- //- // TODO: What this really should do is query the last imported_id- // and since then- let date = monthUtils.subDays(db.fromDateRepr(latestTransaction.date), 31);+ const startDate = monthUtils.dayFromDate(+ dateFns.max([+ // Many GoCardless integrations do not support getting more than 90 days+ // worth of data, so make that the earliest possible limit.+ monthUtils.parseDate(monthUtils.subDays(monthUtils.currentDay(), 90)),- // Never download transactions before the starting date. This was- // when the account was added to the system.- if (date < startingDate) {- date = startingDate;- }+ // Never download transactions before the starting date.+ startingDate,+ ]),+ );let { transactions, accountBalance } = await downloadGoCardlessTransactions(userId,userKey,acctId,bankId,- date,+ startDate,);if (transactions.length === 0) {@@ -789,8 +787,8 @@ export async function syncGoCardlessAccount(return result;});} else {- // Otherwise, download transaction for the past 30 days- const startingDay = monthUtils.subDays(monthUtils.currentDay(), 30);+ // Otherwise, download transaction for the past 90 days+ const startingDay = monthUtils.subDays(monthUtils.currentDay(), 90);const { transactions, startingBalance } =await downloadGoCardlessTransactions(@@ -798,7 +796,7 @@ export async function syncGoCardlessAccount(userKey,acctId,bankId,- dateFns.format(dateFns.parseISO(startingDay), 'yyyy-MM-dd'),+ startingDay,);// We need to add a transaction that represents the startingdiff --git a/upcoming-release-notes/1484.md b/upcoming-release-notes/1484.mdnew file mode 100644index 0000000000..b864ff6e86--- /dev/null+++ b/upcoming-release-notes/1484.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [kyrias]+---++Fetch GoCardless transactions from the last 90 days or since first transaction.