From cfffc6c904305d027bcfc1ab1ea5d509c429f070 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 20 Mar 2023 14:10:31 +0000 Subject: [PATCH] Allow checking pending transactions --- core/clients/aggregators/nordigen.py | 17 +++++++++++++++-- core/management/commands/scheduling.py | 2 +- core/models.py | 11 +++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/clients/aggregators/nordigen.py b/core/clients/aggregators/nordigen.py index 1a90c3d..465f058 100644 --- a/core/clients/aggregators/nordigen.py +++ b/core/clients/aggregators/nordigen.py @@ -305,12 +305,25 @@ class NordigenClient(BaseClient, AggregatorClient): """ path = f"accounts/{account_id}/transactions" response = await self.call(path, schema="Transactions") - parsed = response["booked"] - self.normalise_transactions(parsed, state="booked") + + source = "booked" + + # If requisition is specified, try to get the object + # If present, take the transaction source from there, + # pending or booked. + if req: + requisition = self.instance.get_requisition(req) + if requisition: + source = requisition.transaction_source + + parsed = response[source] + self.normalise_transactions(parsed, state=source) if process: await self.process_transactions(account_id, parsed, req=req) if pending: + if process: + raise Exception("Cannot process and get pending") parsed_pending = response["pending"] self.normalise_transactions(parsed_pending, state="pending") parsed_pending.extend(parsed) diff --git a/core/management/commands/scheduling.py b/core/management/commands/scheduling.py index a5783e2..e0a4273 100644 --- a/core/management/commands/scheduling.py +++ b/core/management/commands/scheduling.py @@ -10,7 +10,7 @@ from core.util import logs log = logs.get_logger("scheduling") -INTERVAL_AGGREGATOR = 5 +INTERVAL_AGGREGATOR = 10 INTERVALS_PLATFORM = [x[0] for x in INTERVAL_CHOICES] diff --git a/core/models.py b/core/models.py index 7dbcccc..e80e0d7 100644 --- a/core/models.py +++ b/core/models.py @@ -163,6 +163,12 @@ class Aggregator(models.Model): aggregator=self, ) + def get_requisition(self, requisition_id): + return Requisition.objects.filter( + aggregator=self, + requisition_id=requisition_id, + ).first() + @classmethod def get_currencies_for_platform(cls, platform): # aggregators = Aggregator.get_for_platform(platform) @@ -191,12 +197,13 @@ class Aggregator(models.Model): requisition = Requisition.objects.filter( aggregator=self, requisition_id=requisition_id ).first() - if requisition: - tx_data["requisition"] = requisition + # if requisition: + # tx_data["requisition"] = requisition return Transaction.objects.create( aggregator=self, account_id=account_id, reconciled=False, + requisition=requisition, **tx_data, )