Fixed checking if all transactions have been fetched by using retrievedTransactionsFromOn (as first retrieved transaction may not is on the first day of the fetched period(

This commit is contained in:
dankito 2020-09-22 04:01:25 +02:00
parent f96e7a4b30
commit 1bc8a93ba4
1 changed files with 6 additions and 4 deletions

View File

@ -354,18 +354,20 @@ open class BankingPresenter(
protected open fun didFetchAllTransactionsStoredOnBankServer(account: IBankAccount<IAccountTransaction>, fetchedTransactions: Collection<IAccountTransaction>): Boolean {
account.customer.countDaysForWhichTransactionsAreKept?.let { countDaysForWhichTransactionsAreKept ->
val firstAccountTransactions = if (account.bookedTransactions.isNotEmpty()) account.bookedTransactions else fetchedTransactions
firstAccountTransactions.map { it.valueDate }.minBy { it.millisSinceEpoch }?.let { dateOfFirstRetrievedTransaction ->
(account.retrievedTransactionsFromOn ?: getDateOfFirstRetrievedTransaction(account.bookedTransactions) ?: getDateOfFirstRetrievedTransaction(fetchedTransactions))?.let { retrievedTransactionsFromOn ->
val dayOfFirstTransactionStoredOnBankServer = Date(Date.today.millisSinceEpoch - countDaysForWhichTransactionsAreKept * OneDayMillis)
return dateOfFirstRetrievedTransaction.isBeforeOrEquals(dayOfFirstTransactionStoredOnBankServer)
return retrievedTransactionsFromOn.isBeforeOrEquals(dayOfFirstTransactionStoredOnBankServer)
}
}
return false
}
protected open fun getDateOfFirstRetrievedTransaction(transactions: Collection<IAccountTransaction>): Date? {
return transactions.map { it.valueDate }.minBy { it.millisSinceEpoch }
}
protected open fun receivedAccountsTransactionChunk(bankAccount: TypedBankAccount, accountTransactionsChunk: List<IAccountTransaction>) {
if (accountTransactionsChunk.isNotEmpty()) {
asyncRunner.runAsync { // don't block retrieving next chunk by blocked saving to db / json