Implement viewing bank balances

This commit is contained in:
2023-03-09 18:09:29 +00:00
parent 1ee3d04ea6
commit 35ffa036ae
7 changed files with 152 additions and 16 deletions

View File

@@ -1,16 +1,18 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from mixins.views import ObjectList, ObjectRead
from mixins.views import ObjectList
from two_factor.views.mixins import OTPRequiredMixin
from core.clients.aggregators.nordigen import NordigenClient
from core.models import Aggregator
from core.util import logs
from core.views.helpers import synchronize_async_helper
log = logs.get_logger(__name__)
class BanksCurrencies(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
"""
Get a list of configured currencies from the banks we use.
Get a list of bank accounts with their details.
"""
list_template = "partials/banks-currencies-list.html"
@@ -36,7 +38,30 @@ class BanksCurrencies(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
return account_info
class BankCurrencyDetails(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
class BanksBalances(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
"""
Get the bank details for the selected currency.
Get the bank balances.
"""
list_template = "partials/banks-balances-list.html"
page_title = "Bank Balances"
context_object_name_singular = "balance"
context_object_name = "balances"
list_url_name = "balances"
list_url_args = ["type"]
def get_queryset(self, **kwargs):
aggregators = Aggregator.objects.filter(user=self.request.user, enabled=True)
account_balances = {}
for aggregator in aggregators:
run = synchronize_async_helper(NordigenClient(aggregator))
balance_map = synchronize_async_helper(run.get_all_balances())
for k, v in balance_map.items():
if k not in account_balances:
account_balances[k] = []
for item in v:
account_balances[k].append(item)
return account_balances