From 8995100754f0c15d3f65819c9f8cc042693c3db2 Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 13 Jun 2020 16:06:51 +0200 Subject: [PATCH] Fixed that if all BICs belong to the same bank but just have a different branch code (last three characters of a BIC), its BankInfo hasn't been returned --- .../banking/ui/presenter/BankingPresenter.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 1fd084b9..3aadaf45 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -443,7 +443,19 @@ open class BankingPresenter( val groupedByBic = searchResult.groupBy { it.bic } - return if (groupedByBic.size == 1) searchResult.first() else null + if (groupedByBic.size == 1) { + return searchResult.first() + } + + // check if all BICs belong to the same bank but may are for different branches + val bicsWithoutBranchCode = groupedByBic.map { it.key.substring(0, 8) }.toSet() + + if (bicsWithoutBranchCode.size == 1) { + return searchResult.firstOrNull { it.bic.endsWith("XXX") } // 'XXX' = primary office + ?: searchResult.first() + } + + return null } open fun searchBanksByNameBankCodeOrCity(query: String?): List {