diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index d82a62abae..cf24358336 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -1996,7 +1996,9 @@ "manualblocks.collection.get", "pubsub.publish.post", "automated-patron-blocks.collection.get", - "circulation-storage.loans-history.collection.get" + "circulation-storage.loans-history.collection.get", + "overdue-fines-policies.item.get", + "overdue-fines-policies.collection.get" ], "visible": false }, @@ -2291,7 +2293,9 @@ "pubsub.publish.post", "configuration.entries.collection.get", "patron-notice.post", - "circulation-storage.loans-history.collection.get" + "circulation-storage.loans-history.collection.get", + "overdue-fines-policies.item.get", + "overdue-fines-policies.collection.get" ], "visible": false }, diff --git a/src/main/java/org/folio/circulation/domain/Loan.java b/src/main/java/org/folio/circulation/domain/Loan.java index 3cfe4827b3..f90b11d7a5 100644 --- a/src/main/java/org/folio/circulation/domain/Loan.java +++ b/src/main/java/org/folio/circulation/domain/Loan.java @@ -743,6 +743,7 @@ public FeeAmount getRemainingFeeFineAmount() { public void closeLoanAsLostAndPaid() { log.debug("closeLoanAsLostAndPaid:: "); closeLoan(CLOSED_LOAN); + changeReturnDate(ClockUtil.getZonedDateTime()); changeItemStatusForItemAndLoan(ItemStatus.LOST_AND_PAID); } diff --git a/src/main/java/org/folio/circulation/services/LostItemFeeChargingService.java b/src/main/java/org/folio/circulation/services/LostItemFeeChargingService.java index d63a2d7099..98fde67018 100644 --- a/src/main/java/org/folio/circulation/services/LostItemFeeChargingService.java +++ b/src/main/java/org/folio/circulation/services/LostItemFeeChargingService.java @@ -24,13 +24,10 @@ import org.folio.circulation.domain.FeeFine; import org.folio.circulation.domain.FeeFineOwner; import org.folio.circulation.domain.Loan; -import org.folio.circulation.domain.Location; import org.folio.circulation.domain.policy.lostitem.LostItemPolicy; import org.folio.circulation.domain.policy.lostitem.itemfee.AutomaticallyChargeableFee; -import org.folio.circulation.domain.representations.DeclareItemLostRequest; import org.folio.circulation.infrastructure.storage.ActualCostRecordRepository; import org.folio.circulation.infrastructure.storage.ServicePointRepository; -import org.folio.circulation.infrastructure.storage.feesandfines.FeeFineOwnerRepository; import org.folio.circulation.infrastructure.storage.feesandfines.FeeFineRepository; import org.folio.circulation.infrastructure.storage.inventory.IdentifierTypeRepository; import org.folio.circulation.infrastructure.storage.inventory.LocationRepository; diff --git a/src/main/java/org/folio/circulation/services/agedtolost/ChargeLostFeesWhenAgedToLostService.java b/src/main/java/org/folio/circulation/services/agedtolost/ChargeLostFeesWhenAgedToLostService.java index 67f8a55bd4..4f6f2372cf 100644 --- a/src/main/java/org/folio/circulation/services/agedtolost/ChargeLostFeesWhenAgedToLostService.java +++ b/src/main/java/org/folio/circulation/services/agedtolost/ChargeLostFeesWhenAgedToLostService.java @@ -53,9 +53,9 @@ import org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository; import org.folio.circulation.infrastructure.storage.users.PatronGroupRepository; import org.folio.circulation.infrastructure.storage.users.UserRepository; -import org.folio.circulation.services.actualcostrecord.ActualCostRecordService; import org.folio.circulation.services.EventPublisher; import org.folio.circulation.services.FeeFineFacade; +import org.folio.circulation.services.actualcostrecord.ActualCostRecordService; import org.folio.circulation.services.support.CreateAccountCommand; import org.folio.circulation.support.Clients; import org.folio.circulation.support.fetching.PageableFetcher; diff --git a/src/test/java/api/handlers/CloseAgedToLostLoanWhenLostItemFeesAreClosedApiTests.java b/src/test/java/api/handlers/CloseAgedToLostLoanWhenLostItemFeesAreClosedApiTests.java index 0df74fb8c4..6cdae78a1d 100644 --- a/src/test/java/api/handlers/CloseAgedToLostLoanWhenLostItemFeesAreClosedApiTests.java +++ b/src/test/java/api/handlers/CloseAgedToLostLoanWhenLostItemFeesAreClosedApiTests.java @@ -22,6 +22,7 @@ import org.folio.circulation.domain.Loan; import org.folio.circulation.domain.policy.Period; import org.folio.circulation.services.agedtolost.LoanToChargeFees; +import org.folio.circulation.support.utils.ClockUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -47,13 +48,17 @@ void shouldCloseLoanWhenAllFeesClosed() { feeFineAccountFixture.payLostItemFee(loan.getId()); feeFineAccountFixture.payLostItemProcessingFee(loan.getId()); + var returnDate = ClockUtil.getZonedDateTime(); + mockClockManagerToReturnFixedDateTime(returnDate); eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loan.getId()); - assertThatLoanIsClosedAsLostAndPaid(); + JsonObject loan = assertThatLoanIsClosedAsLostAndPaid(); + assertThat(loan.getString("returnDate"), is(returnDate.toString())); + mockClockManagerToReturnDefaultDateTime(); List loanClosedEvents = getPublishedEventsAsList(byEventType(LOAN_CLOSED)); assertThat(loanClosedEvents, hasSize(1)); - assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan.getJson())); + assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan)); } @Test @@ -224,9 +229,15 @@ void shouldCloseLoanWhenActualCostRecordIsCancelled() { item = result.getItem(); loan = result.getLoan(); + + var returnDate = ClockUtil.getZonedDateTime(); + mockClockManagerToReturnFixedDateTime(returnDate); cancelActualCostRecord(); + eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loan.getId()); - assertThatLoanIsClosedAsLostAndPaid(); + JsonObject loan = assertThatLoanIsClosedAsLostAndPaid(); + assertThat(loan.getString("returnDate"), is(returnDate.toString())); + mockClockManagerToReturnDefaultDateTime(); } @Test diff --git a/src/test/java/api/handlers/CloseDeclaredLostLoanWhenLostItemFeesAreClosedApiTests.java b/src/test/java/api/handlers/CloseDeclaredLostLoanWhenLostItemFeesAreClosedApiTests.java index f63fb42f21..fcbf37dcad 100644 --- a/src/test/java/api/handlers/CloseDeclaredLostLoanWhenLostItemFeesAreClosedApiTests.java +++ b/src/test/java/api/handlers/CloseDeclaredLostLoanWhenLostItemFeesAreClosedApiTests.java @@ -21,6 +21,7 @@ import org.folio.circulation.domain.ItemStatus; import org.folio.circulation.domain.policy.Period; import org.folio.circulation.support.http.client.Response; +import org.folio.circulation.support.utils.ClockUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -54,12 +55,17 @@ void shouldCloseLoanWhenAllFeesClosed() { feeFineAccountFixture.payLostItemFee(loan.getId()); feeFineAccountFixture.payLostItemProcessingFee(loan.getId()); + var returnDate = ClockUtil.getZonedDateTime(); + mockClockManagerToReturnFixedDateTime(returnDate); eventSubscribersFixture.publishLoanRelatedFeeFineClosedEvent(loan.getId()); - assertThatLoanIsClosedAsLostAndPaid(); + + JsonObject loan = assertThatLoanIsClosedAsLostAndPaid(); + assertThat(loan.getString("returnDate"), is(returnDate.toString())); + mockClockManagerToReturnDefaultDateTime(); List loanClosedEvents = getPublishedEventsAsList(byEventType(LOAN_CLOSED)); assertThat(loanClosedEvents, hasSize(1)); - assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan.getJson())); + assertThat(loanClosedEvents.get(0), isValidLoanClosedEvent(loan)); } @Test diff --git a/src/test/java/api/handlers/CloseLostLoanWhenLostItemFeesAreClosed.java b/src/test/java/api/handlers/CloseLostLoanWhenLostItemFeesAreClosed.java index 245bfb8253..0608ffef1b 100644 --- a/src/test/java/api/handlers/CloseLostLoanWhenLostItemFeesAreClosed.java +++ b/src/test/java/api/handlers/CloseLostLoanWhenLostItemFeesAreClosed.java @@ -7,6 +7,7 @@ import static api.support.matchers.LoanMatchers.isClosed; import static api.support.matchers.LoanMatchers.isOpen; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.time.ZonedDateTime; import java.util.UUID; @@ -78,9 +79,13 @@ protected void payLostItemActualCostFeeAndProcessingFeeAndCheckThatLoanIsClosed( assertThatLoanIsClosedAsLostAndPaid(); } - protected void assertThatLoanIsClosedAsLostAndPaid() { - assertThat(loansFixture.getLoanById(loan.getId()).getJson(), isClosed()); + protected JsonObject assertThatLoanIsClosedAsLostAndPaid() { + JsonObject loan = loansFixture.getLoanById(this.loan.getId()).getJson(); + assertThat(loan, isClosed()); + assertNotNull(loan.getString("returnDate")); assertThat(itemsClient.getById(item.getId()).getJson(), isLostAndPaid()); + + return loan; } protected void assertThatLoanIsOpenAndLost() {