Implemented filtering out duplicate transactions as some banks return some transactions multiple times in MT940 response

This commit is contained in:
dankito 2020-09-16 15:07:21 +02:00
parent 3d33af68a1
commit 0e0a7b5207
7 changed files with 70 additions and 6 deletions

View File

@ -377,7 +377,7 @@ open class FinTsClient(
val message = messageBuilder.createGetTransactionsMessage(parameter, account, dialogContext) val message = messageBuilder.createGetTransactionsMessage(parameter, account, dialogContext)
val bookedTransactions = mutableListOf<AccountTransaction>() val bookedTransactions = mutableSetOf<AccountTransaction>() // some banks like Postbank return some transactions multiple times -> remove these
var remainingMt940String = "" var remainingMt940String = ""
dialogContext.abortIfTanIsRequired = parameter.abortIfTanIsRequired dialogContext.abortIfTanIsRequired = parameter.abortIfTanIsRequired
@ -398,7 +398,7 @@ open class FinTsClient(
callback(GetTransactionsResponse( callback(GetTransactionsResponse(
response, response,
bookedTransactions, bookedTransactions.toList(),
listOf(), // TODO: implement parsing MT942 listOf(), // TODO: implement parsing MT942
balance balance
) )

View File

@ -49,6 +49,37 @@ open class AccountTransaction(
null, "", "", null, null, "", null) null, "", "", null, null, "", null)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is AccountTransaction) return false
if (account != other.account) return false
if (amount != other.amount) return false
if (unparsedUsage != other.unparsedUsage) return false
if (bookingDate != other.bookingDate) return false
if (otherPartyName != other.otherPartyName) return false
if (otherPartyBankCode != other.otherPartyBankCode) return false
if (otherPartyAccountId != other.otherPartyAccountId) return false
if (bookingText != other.bookingText) return false
if (valueDate != other.valueDate) return false
return true
}
override fun hashCode(): Int {
var result = account.hashCode()
result = 31 * result + amount.hashCode()
result = 31 * result + unparsedUsage.hashCode()
result = 31 * result + bookingDate.hashCode()
result = 31 * result + (otherPartyName?.hashCode() ?: 0)
result = 31 * result + (otherPartyBankCode?.hashCode() ?: 0)
result = 31 * result + (otherPartyAccountId?.hashCode() ?: 0)
result = 31 * result + (bookingText?.hashCode() ?: 0)
result = 31 * result + valueDate.hashCode()
return result
}
override fun toString(): String { override fun toString(): String {
return "$valueDate $amount $otherPartyName: $unparsedUsage" return "$valueDate $amount $otherPartyName: $unparsedUsage"
} }

View File

@ -8,6 +8,20 @@ open class Currency(
internal constructor() : this("") // for object deserializers internal constructor() : this("") // for object deserializers
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Currency) return false
if (code != other.code) return false
return true
}
override fun hashCode(): Int {
return code.hashCode()
}
override fun toString(): String { override fun toString(): String {
return code return code
} }

View File

@ -9,5 +9,5 @@ open class GetTransactionsParameter(
val toDate: Date? = null, val toDate: Date? = null,
val maxCountEntries: Int? = null, val maxCountEntries: Int? = null,
val abortIfTanIsRequired: Boolean = false, val abortIfTanIsRequired: Boolean = false,
val retrievedChunkListener: ((List<AccountTransaction>) -> Unit)? = null val retrievedChunkListener: ((Collection<AccountTransaction>) -> Unit)? = null
) )

View File

@ -16,6 +16,24 @@ open class Money(
get() = "$amount $currency" get() = "$amount $currency"
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Money) return false
if (amount != other.amount) return false
if (currency != other.currency) return false
return true
}
override fun hashCode(): Int {
var result = amount.hashCode()
result = 31 * result + currency.hashCode()
return result
}
override fun toString(): String { override fun toString(): String {
return displayString return displayString
} }

View File

@ -82,8 +82,9 @@ open class fints4kBankingClient(
} }
else { else {
val mappedParameter = GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate, val mappedParameter = GetTransactionsParameter(parameter.alsoRetrieveBalance, parameter.fromDate,
parameter.toDate, null, parameter.abortIfTanIsRequired, parameter.toDate, null, parameter.abortIfTanIsRequired) {
{ parameter.retrievedChunkListener?.invoke(mapper.mapTransactions(bankAccount, it)) } ) parameter.retrievedChunkListener?.invoke(mapper.mapTransactions(bankAccount, it))
}
doGetTransactionsAsync(mappedParameter, account, bankAccount, callback) doGetTransactionsAsync(mappedParameter, account, bankAccount, callback)
} }

View File

@ -180,7 +180,7 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) {
} }
open fun mapTransactions(bankAccount: TypedBankAccount, transactions: List<net.dankito.banking.fints.model.AccountTransaction>): List<IAccountTransaction> { open fun mapTransactions(bankAccount: TypedBankAccount, transactions: Collection<net.dankito.banking.fints.model.AccountTransaction>): List<IAccountTransaction> {
return transactions.map { mapTransaction(bankAccount, it) } return transactions.map { mapTransaction(bankAccount, it) }
} }