From 12c36dae08496d6cf896646af49ce2a8fdd0ca19 Mon Sep 17 00:00:00 2001 From: Damien Date: Fri, 21 Jun 2024 11:44:00 -0400 Subject: [PATCH] [MODFISTO-488] Fixed encumbrance changes after cancelling a payment or credit --- .../transactions/batch/BatchPaymentCreditService.java | 6 ++++-- .../org/folio/service/transactions/PaymentCreditTest.java | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/folio/service/transactions/batch/BatchPaymentCreditService.java b/src/main/java/org/folio/service/transactions/batch/BatchPaymentCreditService.java index 77594d0d..267610cd 100644 --- a/src/main/java/org/folio/service/transactions/batch/BatchPaymentCreditService.java +++ b/src/main/java/org/folio/service/transactions/batch/BatchPaymentCreditService.java @@ -76,10 +76,12 @@ private void updateEncumbranceToCancelTransaction(Transaction transaction, Trans double amount = encumbrance.getAmount(); if (transaction.getTransactionType() == PAYMENT) { expended = subtractMoney(expended, transaction.getAmount(), currency); - amount = sumMoney(amount, transaction.getAmount(), currency); + if (encumbrance.getEncumbrance().getStatus() == Encumbrance.Status.UNRELEASED) { + amount = sumMoney(amount, transaction.getAmount(), currency); + } } else { credited = subtractMoney(credited, transaction.getAmount(), currency); - if (Encumbrance.Status.RELEASED != encumbrance.getEncumbrance().getStatus()) { + if (encumbrance.getEncumbrance().getStatus() == Encumbrance.Status.UNRELEASED) { amount = subtractMoney(amount, transaction.getAmount(), currency); } } diff --git a/src/test/java/org/folio/service/transactions/PaymentCreditTest.java b/src/test/java/org/folio/service/transactions/PaymentCreditTest.java index a8fe2941..d0b4f757 100644 --- a/src/test/java/org/folio/service/transactions/PaymentCreditTest.java +++ b/src/test/java/org/folio/service/transactions/PaymentCreditTest.java @@ -589,7 +589,8 @@ void testCancelPaymentWithLinkedEncumbrance(VertxTestContext testContext) { assertThat(savedEncumbrance.getTransactionType(), equalTo(ENCUMBRANCE)); assertThat(savedEncumbrance.getEncumbrance().getStatus(), equalTo(RELEASED)); assertNotNull(savedEncumbrance.getMetadata().getUpdatedDate()); - assertThat(savedEncumbrance.getAmount(), equalTo(5d)); + assertThat(savedEncumbrance.getAmount(), equalTo(0d)); + assertThat(savedEncumbrance.getEncumbrance().getInitialAmountEncumbered(), equalTo(5d)); assertThat(savedEncumbrance.getEncumbrance().getAmountAwaitingPayment(), equalTo(0d)); assertThat(savedEncumbrance.getEncumbrance().getAmountExpended(), equalTo(0d)); @@ -689,6 +690,7 @@ void testCancelCreditWithLinkedEncumbrance(VertxTestContext testContext) { assertThat(savedEncumbrance.getEncumbrance().getStatus(), equalTo(RELEASED)); assertNotNull(savedEncumbrance.getMetadata().getUpdatedDate()); assertThat(savedEncumbrance.getAmount(), equalTo(0d)); + assertThat(savedEncumbrance.getEncumbrance().getInitialAmountEncumbered(), equalTo(5d)); assertThat(savedEncumbrance.getEncumbrance().getAmountAwaitingPayment(), equalTo(0d)); assertThat(savedEncumbrance.getEncumbrance().getAmountExpended(), equalTo(5d)); assertThat(savedEncumbrance.getEncumbrance().getAmountCredited(), equalTo(0d));