From 2a626a8b7c18a8e5535e4a87e88153016e44d758 Mon Sep 17 00:00:00 2001 From: dankl Date: Sat, 25 Jan 2020 18:08:40 +0100 Subject: [PATCH] Fixed that balance of selected accounts got calculated wrong (balances of accounts with multiple bank accounts got added multiple times) --- .../net/dankito/banking/ui/presenter/MainWindowPresenter.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt index f51419f1..7aaeb602 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt @@ -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 { + return singleBalances.fold(BigDecimal.ZERO) { acc, e -> acc + e } + } + open fun addAccountsChangedListener(listener: (List) -> Unit): Boolean { return accountsChangedListeners.add(listener)