The personal finance app for everyone (by everyone)
Ruby
fix: Properly compute credit card balance for Enable Banking accounts (#663)
Alessio Cappa6ec03e93f485
diff --git a/app/models/enable_banking_account/processor.rb b/app/models/enable_banking_account/processor.rbindex 3b5741b17c..ada55916f9 100644--- a/app/models/enable_banking_account/processor.rb+++ b/app/models/enable_banking_account/processor.rb@@ -38,8 +38,12 @@ class EnableBankingAccount::Processoraccount = enable_banking_account.current_accountbalance = enable_banking_account.current_balance || 0+ # For credit cards, compute balance based on credit limit+ if account.accountable_type == "CreditCard"+ available_credit = account.accountable.available_credit || 0+ balance = available_credit - balance# For liability accounts, ensure positive balances- if account.accountable_type == "CreditCard" || account.accountable_type == "Loan"+ elsif account.accountable_type == "Loan"balance = -balanceenddiff --git a/app/models/enable_banking_item/importer.rb b/app/models/enable_banking_item/importer.rbindex 60b1e4d041..178d146f29 100644--- a/app/models/enable_banking_item/importer.rb+++ b/app/models/enable_banking_item/importer.rb@@ -134,9 +134,11 @@ class EnableBankingItem::Importerbalances = balance_data[:balances] || []return if balances.empty?- # Find the most relevant balance (prefer "closingBooked" or "expected")- balance = balances.find { |b| b[:balance_type] == "closingBooked" } ||- balances.find { |b| b[:balance_type] == "expected" } ||+ # Find the most relevant balance (prefer "ITAV" or "CLAV" types)+ balance = balances.find { |b| b[:balance_type] == "ITAV" } ||+ balances.find { |b| b[:balance_type] == "CLAV" } ||+ balances.find { |b| b[:balance_type] == "ITBD" } ||+ balances.find { |b| b[:balance_type] == "CLBD" } ||balances.firstif balance.present?