From: Magnus Hagander Date: Tue, 12 Mar 2024 14:49:14 +0000 (+0100) Subject: Delay further UNKNOWN transferwise transactions X-Git-Url: http://git.postgresql.org/gitweb/static/connections.php?a=commitdiff_plain;h=8878140450fc8e2d7902ea0a53dc4d1ef26fcf7b;p=pgeu-system.git Delay further UNKNOWN transferwise transactions If we receive a transaction with type UNKNOWN and an empty description, delay processing it for up to 2 hours. It seems some data is simply not available immediately. The 2 hours is a guess on how long, and hopefully a decent mix between working and delay. --- diff --git a/postgresqleu/transferwise/management/commands/transferwise_fetch_transactions.py b/postgresqleu/transferwise/management/commands/transferwise_fetch_transactions.py index 3c253ffe..43745b98 100644 --- a/postgresqleu/transferwise/management/commands/transferwise_fetch_transactions.py +++ b/postgresqleu/transferwise/management/commands/transferwise_fetch_transactions.py @@ -16,7 +16,7 @@ from postgresqleu.invoices.models import InvoicePaymentMethod from postgresqleu.transferwise.models import TransferwiseTransaction, TransferwiseRefund from postgresqleu.transferwise.models import TransferwisePayout -from datetime import timedelta +from datetime import datetime, timedelta import re @@ -43,6 +43,16 @@ class Command(BaseCommand): for t in api.get_transactions(): # We will re-fetch most transactions, so only create them if they are not # already there. + + # Seems transactions come in as UNKNOWN and with no text first, and then we get + # more details later. So if we see one of those, postpone it for up to 2 hours + # (random magic value). + if t['details']['type'] == 'UNKNOWN' and \ + t['details']['description'] == '' and \ + datetime.now() - api.parse_datetime(t['date']) < timedelta(hours=2): + print("Skipping UNKNOWN transaction {}, no data and less than 2 hours old".format(t['referenceNumber'])) + continue + trans, created = TransferwiseTransaction.objects.get_or_create( paymentmethod=method, twreference=t['referenceNumber'],