Negate *all* wise transactions based on "Sent by ..." in text
authorMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 12:46:38 +0000 (14:46 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 12:46:38 +0000 (14:46 +0200)
Turns out we need to do this both for primary ands secondary amounts
(which makes sense). Clarify the comment a bit further after more
research that still shows Wise API returns that incoming payments are
actually outgoing. Sigh.

postgresqleu/transferwise/api.py

index a61278e6ae995596b6a797f3075947cd21a161ab..ed8c40a976193485bb8eda97e3df39db6bb313a5 100644 (file)
@@ -143,9 +143,13 @@ class TransferwiseApi(object):
                     # Yes, the transfer will actually have a positive amount even if it's a withdrawal.
                     # No, this is not indicated anywhere, since the "target account id" that would
                     # indicate it, points to the wrong account for incoming payments.
+                    # Oh, and the status is *always* set to `outgoing_payment_sent`, even for incoming
+                    # payments. I guess all payments are outgoing from *something*.
                     # Let's do a wild gamble and assume the description is always this...
                     if activity.get('description', '').startswith('Sent by '):
-                        amount = -amount
+                        negatizer = -1
+                    else:
+                        negatizer = 1
 
                     # We also need to look at the amount in the activity, as it might be different
                     # if there are fees.
@@ -167,7 +171,7 @@ class TransferwiseApi(object):
                     yield {
                         'id': 'TRANSFER-{}'.format(activity['resource']['id']),
                         'datetime': details['created'],
-                        'amount': amount,
+                        'amount': amount * negatizer,
                         'feeamount': 0,  # XXX!
                         'transtype': 'TRANSFER',
                         'paymentref': details['reference'],