Handle Adyen settlement batches with just balancetransfers
authorMagnus Hagander <magnus@hagander.net>
Wed, 7 Nov 2018 10:15:39 +0000 (11:15 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 7 Nov 2018 10:15:39 +0000 (11:15 +0100)
If we have a batch with just balance transfers going in and out of
exactly the same amount, an exception would be thrown because they'd be
summarized into 0.

Fix that by splitting apart incoming and outgoing balance transfers,
making each one of them non-zero.

For most normal settlement batches this was not a problem since
they will only have one Balancetranfer row, and it will be balanced
against the other types of entries.

postgresqleu/adyen/management/commands/process_adyen_reports.py

index 7c154e1c9606518f216419e534ef26fa084e4bda..7364c8e05ce81bc5ebe5bdf30b0450bc0622e760 100644 (file)
@@ -137,6 +137,12 @@ class Command(BaseCommand):
                types = {}
                for l in reader:
                        t = l['Type']
+                       if t == 'Balancetransfer':
+                               # Balance transfer is special -- we can have two of them that evens out,
+                               # but we need to separate in and out
+                               if Decimal(l['Net Debit (NC)'] or 0) > 0:
+                                       t = "Balancetransfer2"
+
                        lamount = Decimal(l['Net Credit (NC)'] or 0) - Decimal(l['Net Debit (NC)'] or 0)
                        if types.has_key(t):
                                types[t] += lamount
@@ -164,7 +170,7 @@ class Command(BaseCommand):
                        elif t == 'MerchantPayout':
                                # Amount directly into our checking account
                                acctrows.append((settings.ACCOUNTING_ADYEN_PAYOUT_ACCOUNT, accstr, -amount, None))
-                       elif t == 'DepositCorrection' or t == 'Balancetransfer':
+                       elif t == 'DepositCorrection' or t == 'Balancetransfer' or t == 'Balancetransfer2':
                                # Modification of our deposit account - in either direction!
                                acctrows.append((settings.ACCOUNTING_ADYEN_MERCHANT_ACCOUNT, accstr, -amount, None))
                        elif t == 'InvoiceDeduction':