43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
|
from abc import ABC
|
||
|
|
||
|
|
||
|
class AggregatorClient(ABC):
|
||
|
def store_account_info(self, account_infos):
|
||
|
# account_infos = {
|
||
|
# bank: accounts
|
||
|
# for bank, accounts in account_info.items()
|
||
|
# for account in accounts
|
||
|
# #if account["account_id"] in self.banks
|
||
|
# }
|
||
|
# For each bank
|
||
|
for bank, accounts in account_infos.items():
|
||
|
# Iterate the accounts
|
||
|
for index, account in enumerate(list(accounts)):
|
||
|
if "account_number" not in account:
|
||
|
account_infos[bank][index]["account_number"] = {}
|
||
|
fields = ["sort_code", "number", "iban"]
|
||
|
for field in fields:
|
||
|
if field in account:
|
||
|
account_infos[bank][index]["account_number"][
|
||
|
field
|
||
|
] = account[field]
|
||
|
del account_infos[bank][index][field]
|
||
|
# if len(account["account_number"]) == 1:
|
||
|
# account_infos[bank].remove(account)
|
||
|
currencies = [
|
||
|
account["currency"]
|
||
|
for bank, accounts in account_infos.items()
|
||
|
for account in accounts
|
||
|
]
|
||
|
for bank, accounts in account_infos.items():
|
||
|
if not self.instance.account_info:
|
||
|
self.instance.account_info = {}
|
||
|
self.instance.account_info[bank] = []
|
||
|
for account in accounts:
|
||
|
self.instance.account_info[bank].append(account)
|
||
|
# self.account_info = account_infos
|
||
|
self.currencies = currencies
|
||
|
|
||
|
self.instance.currencies = currencies
|
||
|
self.instance.save()
|