From abba21688e5c1c1d2f01118d3c433490ab80c7e4 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 9 Apr 2024 12:22:43 +0200 Subject: [PATCH] determine reverse entry for asset transaction adjustment in legacy data import --- .../hs/office/migration/ImportOfficeData.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java index 47e5a6ba..6e2f23f7 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java @@ -395,8 +395,8 @@ public class ImportOfficeData extends ContextBasedTest { 34001=CoopAssetsTransaction(M-1002000: 2016-12-31, CLEARING, -8.00, legacy data import, for cancellation D), 34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, legacy data import, for cancellation D), 34003=CoopAssetsTransaction(M-1002000: 2016-12-31, LOSS, -20.00, legacy data import, for cancellation D), - 35001=CoopAssetsTransaction(M-1909000: 2024-01-15, DEPOSIT, 128.00, legacy data import, for subscription E), - 35002=CoopAssetsTransaction(M-1909000: 2024-01-20, ADJUSTMENT, -128.00, legacy data import, chargeback for subscription E) + 35001=CoopAssetsTransaction(M-1909000: 2024-01-15, DEPOSIT, 128.00, legacy data import, for subscription E, M-1909000:-128.00), + 35002=CoopAssetsTransaction(M-1909000: 2024-01-20, ADJUSTMENT, -128.00, legacy data import, chargeback for subscription E, M-1909000:+128.00) } """); } @@ -852,6 +852,18 @@ public class ImportOfficeData extends ContextBasedTest { .reference("legacy data import") // TODO.spec: or use value from comment column? .build(); + if (assetTransaction.getTransactionType() == HsOfficeCoopAssetsTransactionType.ADJUSTMENT) { + final var negativeValue = assetTransaction.getAssetValue().negate(); + final var reverseEntry = coopAssets.values().stream().filter(a -> + a.getTransactionType() != HsOfficeCoopAssetsTransactionType.ADJUSTMENT && + a.getMembership() == assetTransaction.getMembership() && + a.getAssetValue().equals(negativeValue)) + .findAny() + .orElseThrow(() -> new IllegalStateException("cannot determine asset reverse entry for adjustment " + assetTransaction)); + reverseEntry.setReverseEntry(assetTransaction); + assetTransaction.setReverseEntry(reverseEntry); + } + coopAssets.put(rec.getInteger("member_asset_id"), assetTransaction); }); }