From 1c0cbba85561948f60116c8ebe66de9b82eefb31 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 11 Mar 2023 11:45:09 +0000 Subject: [PATCH] Show pending transactions --- core/clients/aggregators/nordigen.py | 16 ++++++++++++---- .../partials/banks-transactions-list.html | 15 ++++++++++++++- core/views/banks.py | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/clients/aggregators/nordigen.py b/core/clients/aggregators/nordigen.py index 4013300..b494faa 100644 --- a/core/clients/aggregators/nordigen.py +++ b/core/clients/aggregators/nordigen.py @@ -247,7 +247,7 @@ class NordigenClient(BaseClient, AggregatorClient): totals[currency] = amount return totals - def normalise_transactions(self, transactions): + def normalise_transactions(self, transactions, state=None): for transaction in transactions: # Rename ID if "transactionId" in transaction: @@ -275,6 +275,8 @@ class NordigenClient(BaseClient, AggregatorClient): transaction["amount"] = float(transaction["transactionAmount"]["amount"]) transaction["currency"] = transaction["transactionAmount"]["currency"] + if state: + transaction["state"] = state del transaction["transactionAmount"] if transaction["remittanceInformationUnstructuredArray"]: @@ -289,7 +291,7 @@ class NordigenClient(BaseClient, AggregatorClient): else: raise Exception(f"No way to get reference: {transaction}") - async def get_transactions(self, account_id, process=False): + async def get_transactions(self, account_id, process=False, pending=False): """ Get all transactions for an account. :param account_id: account to fetch transactions for @@ -298,9 +300,15 @@ class NordigenClient(BaseClient, AggregatorClient): """ path = f"accounts/{account_id}/transactions" response = await self.call(path, schema="Transactions") - + print("RESP", response["pending"]) parsed = response["booked"] - self.normalise_transactions(parsed) + self.normalise_transactions(parsed, state="booked") + if process: await self.process_transactions(parsed) + if pending: + parsed_pending = response["pending"] + self.normalise_transactions(parsed_pending, state="pending") + parsed_pending.extend(parsed) + parsed = parsed_pending return parsed diff --git a/core/templates/partials/banks-transactions-list.html b/core/templates/partials/banks-transactions-list.html index 26419bf..5305518 100644 --- a/core/templates/partials/banks-transactions-list.html +++ b/core/templates/partials/banks-transactions-list.html @@ -3,6 +3,7 @@ {% get_last_invalidation 'core.Aggregator' as last %} {% include 'mixins/partials/notify.html' %} {# cache 600 objects_banks_transactions request.user.id object_list type last #} + amount + {% for item in object_list %} + onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.transaction_id }}');"> @@ -50,6 +52,17 @@ + {% endfor %} diff --git a/core/views/banks.py b/core/views/banks.py index 17fe36d..e2deae5 100644 --- a/core/views/banks.py +++ b/core/views/banks.py @@ -121,5 +121,5 @@ class BanksTransactions(LoginRequiredMixin, OTPRequiredMixin, ObjectList): return self.render_to_response(context) run = synchronize_async_helper(NordigenClient(aggregator)) - transactions = synchronize_async_helper(run.get_transactions(account_id)) + transactions = synchronize_async_helper(run.get_transactions(account_id, pending=True)) return transactions
currency referencestate
{{ item.amount }} {{ item.currency }} {{ item.reference }} + {% if item.state == 'pending' %} + + + + {% elif item.state == 'booked' %} + + + + {% endif %} +