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

This commit is contained in:
dankito 2020-06-13 16:06:51 +02:00
parent 996204f54f
commit 8995100754
1 changed files with 13 additions and 1 deletions

View File

@ -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<BankInfo> {