Skip to content

Commit 6912c08

Browse files
authored
Fetch GoCardless transactions from the last 90 days or since first transaction (#1484)
Most banks allow up to 90 days of transactions, and so we try to fetch up to 90 days of transactions or transactions since the first transaction in the Actual account, whichever is shortest. This lets users get a clean start based on their selected starting balances date. Signed-off-by: Johannes Löthberg <[email protected]>
1 parent 8a6c54c commit 6912c08

File tree

2 files changed

+22
-18
lines changed
  • packages/loot-core/src/server/accounts
  • upcoming-release-notes

2 files changed

+22
-18
lines changed

packages/loot-core/src/server/accounts/sync.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -752,29 +752,27 @@ export async function syncGoCardlessAccount(
752752
'SELECT date FROM v_transactions WHERE account = ? ORDER BY date ASC LIMIT 1',
753753
[id],
754754
);
755-
const startingDate = db.fromDateRepr(startingTransaction.date);
756-
// assert(startingTransaction)
755+
const startingDate = monthUtils.parseDate(
756+
db.fromDateRepr(startingTransaction.date),
757+
);
757758

758-
// Get all transactions since the latest transaction, plus any 5
759-
// days before the latest transaction. This gives us a chance to
760-
// resolve any transactions that were entered manually.
761-
//
762-
// TODO: What this really should do is query the last imported_id
763-
// and since then
764-
let date = monthUtils.subDays(db.fromDateRepr(latestTransaction.date), 31);
759+
const startDate = monthUtils.dayFromDate(
760+
dateFns.max([
761+
// Many GoCardless integrations do not support getting more than 90 days
762+
// worth of data, so make that the earliest possible limit.
763+
monthUtils.parseDate(monthUtils.subDays(monthUtils.currentDay(), 90)),
765764

766-
// Never download transactions before the starting date. This was
767-
// when the account was added to the system.
768-
if (date < startingDate) {
769-
date = startingDate;
770-
}
765+
// Never download transactions before the starting date.
766+
startingDate,
767+
]),
768+
);
771769

772770
let { transactions, accountBalance } = await downloadGoCardlessTransactions(
773771
userId,
774772
userKey,
775773
acctId,
776774
bankId,
777-
date,
775+
startDate,
778776
);
779777

780778
if (transactions.length === 0) {
@@ -789,16 +787,16 @@ export async function syncGoCardlessAccount(
789787
return result;
790788
});
791789
} else {
792-
// Otherwise, download transaction for the past 30 days
793-
const startingDay = monthUtils.subDays(monthUtils.currentDay(), 30);
790+
// Otherwise, download transaction for the past 90 days
791+
const startingDay = monthUtils.subDays(monthUtils.currentDay(), 90);
794792

795793
const { transactions, startingBalance } =
796794
await downloadGoCardlessTransactions(
797795
userId,
798796
userKey,
799797
acctId,
800798
bankId,
801-
dateFns.format(dateFns.parseISO(startingDay), 'yyyy-MM-dd'),
799+
startingDay,
802800
);
803801

804802
// We need to add a transaction that represents the starting

upcoming-release-notes/1484.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Enhancements
3+
authors: [kyrias]
4+
---
5+
6+
Fetch GoCardless transactions from the last 90 days or since first transaction.

0 commit comments

Comments
 (0)