From 4211d3c10a3a53ed9bb85a4970f366311db39cab Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 14 Mar 2023 14:06:54 +0000 Subject: [PATCH] Group currency list by requisition --- core/clients/aggregator.py | 4 ++- core/clients/aggregators/nordigen.py | 6 ++-- core/models.py | 34 +++++++++++++++++++ core/templates/partials/aggregator-info.html | 2 +- core/templates/partials/aggregator-list.html | 2 +- .../partials/banks-currencies-list.html | 2 +- core/templates/partials/platform-list.html | 2 +- core/views/banks.py | 7 ++-- 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/core/clients/aggregator.py b/core/clients/aggregator.py index c075d96..3e1c14e 100644 --- a/core/clients/aggregator.py +++ b/core/clients/aggregator.py @@ -76,7 +76,9 @@ class AggregatorClient(ABC): ) # New transaction await notify.sendmsg( - f"New transaction: {orjson.dumps(tx_cast)}", title="New transaction" + self.instance.user, + f"New transaction: {orjson.dumps(tx_cast)}", + title="New transaction", ) await self.transaction(platforms, tx_obj) else: diff --git a/core/clients/aggregators/nordigen.py b/core/clients/aggregators/nordigen.py index 877aa1c..a073124 100644 --- a/core/clients/aggregators/nordigen.py +++ b/core/clients/aggregators/nordigen.py @@ -124,7 +124,7 @@ class NordigenClient(BaseClient, AggregatorClient): # ownernames = loads(settings.Nordigen.OwnerNames) # return ownernames - async def get_account(self, account_id): + async def get_account(self, req_id, account_id): """ Get details of an account. :param account_id: account ID""" @@ -148,6 +148,7 @@ class NordigenClient(BaseClient, AggregatorClient): # Let's add the account ID so we can reference it later parsed["account_id"] = account_id parsed["aggregator_id"] = str(self.instance.id) + parsed["requisition_id"] = str(req_id) return parsed async def get_all_account_info(self, requisition=None, store=False): @@ -157,10 +158,11 @@ class NordigenClient(BaseClient, AggregatorClient): else: requisitions = [await self.get_requisition(requisition)] + print("REQS", requisitions) for req in requisitions: accounts = req["accounts"] for account_id in accounts: - account_info = await self.get_account(account_id) + account_info = await self.get_account(req["id"], account_id) if not account_info: continue if req["institution_id"] in to_return: diff --git a/core/models.py b/core/models.py index 4dabe59..ce04f20 100644 --- a/core/models.py +++ b/core/models.py @@ -25,6 +25,11 @@ INTERVAL_CHOICES = ( (86400, "Every day"), ) +TRANSACTION_SOURCE_CHOICES = ( + ("booked", "Booked"), + ("pending", "Pending"), +) + class User(AbstractUser): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) @@ -187,6 +192,8 @@ class Platform(models.Model): base_usd = models.FloatField(default=2800) withdrawal_trigger = models.FloatField(default=200) + # payees = models.ManyToManyField(Wallet, blank=True) + enabled = models.BooleanField(default=True) def __str__(self): @@ -471,6 +478,33 @@ class Trade(models.Model): release_response = models.JSONField(default=dict) +# class BankAccount(models.Model): +# """ +# Extra information for an account. +# """ +# account_id = models.CharField(max_length=255) +# payment_details = models.TextField() + +# enabled = models.BooleanField(default=True) + + +class Requisition(models.Model): + """ + A requisition for an Aggregator + """ + + aggregator = models.ForeignKey(Aggregator, on_delete=models.CASCADE) + requisition_id = models.CharField(max_length=255) + payment_details = models.TextField() + + transaction_source = models.CharField( + max_length=255, choices=TRANSACTION_SOURCE_CHOICES + ) + + # throughput = models.FloatField(default=0) + # payees = models.ManyToManyField(Wallet, blank=True) + + assets = { "XMR": "Monero", "BTC": "Bitcoin", diff --git a/core/templates/partials/aggregator-info.html b/core/templates/partials/aggregator-info.html index 28aa55b..61ccaef 100644 --- a/core/templates/partials/aggregator-info.html +++ b/core/templates/partials/aggregator-info.html @@ -17,7 +17,7 @@ + onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}');"> diff --git a/core/templates/partials/aggregator-list.html b/core/templates/partials/aggregator-list.html index 83d6d24..4260499 100644 --- a/core/templates/partials/aggregator-list.html +++ b/core/templates/partials/aggregator-list.html @@ -23,7 +23,7 @@ + onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}');"> diff --git a/core/templates/partials/banks-currencies-list.html b/core/templates/partials/banks-currencies-list.html index 6451220..a417e85 100644 --- a/core/templates/partials/banks-currencies-list.html +++ b/core/templates/partials/banks-currencies-list.html @@ -7,7 +7,7 @@ {# cache 600 objects_banks_currencies request.user.id object_list type last #} {% for bank, accounts in object_list.items %} -

{{ bank }}

+

{{ bank.0 }} {{ bank.1 }}

+ onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}');"> diff --git a/core/views/banks.py b/core/views/banks.py index afeca17..773a320 100644 --- a/core/views/banks.py +++ b/core/views/banks.py @@ -44,10 +44,11 @@ class BanksCurrencies(LoginRequiredMixin, OTPRequiredMixin, ObjectList): account_info = {} for agg in aggregators: for bank, accounts in agg.account_info.items(): - if bank not in account_info: - account_info[bank] = [] for account in accounts: - account_info[bank].append(account) + ident = (bank, account["requisition_id"]) + if ident not in account_info: + account_info[ident] = [] + account_info[ident].append(account) return account_info