Fixed that balance of selected accounts got calculated wrong (balances of accounts with multiple bank accounts got added multiple times)

This commit is contained in:
dankl 2020-01-25 18:08:40 +01:00 committed by dankito
parent 69dea311bf
commit 2a626a8b7c
1 changed files with 5 additions and 1 deletions

View File

@ -319,7 +319,7 @@ open class MainWindowPresenter(
get() = getAccountTransactionsForAccounts(selectedBankAccounts.map { it.account }.toSet())
open val balanceOfSelectedBankAccounts: BigDecimal
get() = getBalanceForAccounts(selectedBankAccounts.map { it.account }.toSet())
get() = sumBalance(selectedBankAccounts.map { it.balance })
open fun selectedAllBankAccounts() {
setSelectedBankAccounts(bankAccounts)
@ -403,6 +403,10 @@ open class MainWindowPresenter(
return accounts.map { it.balance }.fold(BigDecimal.ZERO) { acc, e -> acc + e }
}
protected open fun sumBalance(singleBalances: Collection<BigDecimal>): BigDecimal {
return singleBalances.fold(BigDecimal.ZERO) { acc, e -> acc + e }
}
open fun addAccountsChangedListener(listener: (List<Account>) -> Unit): Boolean {
return accountsChangedListeners.add(listener)