Search in sources :

Example 16 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId.

@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId() {
    Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    FundDistribution distribution1 = new FundDistribution().withFundId(fund1.getId());
    FundDistribution distribution2 = new FundDistribution().withFundId(fund2.getId());
    FundDistribution distribution3 = new FundDistribution().withFundId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withFundDistribution(distribution1);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withFundDistribution(distribution2);
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withFundDistribution(distribution3);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3);
    Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund1.getId());
    Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund2.getId());
    when(budgetService.fetchBudgetsByFundIds(anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(budget1, budget2)));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withBudgets(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("budget", nullValue()), hasProperty("ledgerId", nullValue()))));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 17 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class ReEncumbranceHoldersBuilderTest method shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFiscalYearNull.

@Test
void shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFiscalYearNull() {
    String ledgerId1 = UUID.randomUUID().toString();
    String ledgerId2 = UUID.randomUUID().toString();
    Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId1);
    Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId2);
    Fund fund3 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId2);
    Fund fund4 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId());
    ReEncumbranceHolder holder4 = new ReEncumbranceHolder().withLedgerId(fund4.getLedgerId());
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3, holder4);
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund1.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund2.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund3.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund4.getLedgerId())))));
    verify(rolloverRetrieveService, never()).getLedgerFyRollovers(anyString(), anyList(), any());
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 18 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class OrderReEncumberServiceTest method testPopulateNeedReEncumberField.

@Test
void testPopulateNeedReEncumberField() {
    // given
    CompositePurchaseOrder order = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
    String ledgerId = UUID.randomUUID().toString();
    Fund sampleFund = new Fund().withLedgerId(UUID.randomUUID().toString()).withFundStatus(Fund.FundStatus.ACTIVE).withCode(UUID.randomUUID().toString());
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId);
    LedgerFiscalYearRolloverErrorCollection ledgerFiscalYearRolloverErrors = new LedgerFiscalYearRolloverErrorCollection().withLedgerFiscalYearRolloverErrors(Collections.singletonList(new LedgerFiscalYearRolloverError()));
    CompositePoLine line = order.getCompositePoLines().get(0);
    FundDistribution fundDistribution1 = line.getFundDistribution().get(0);
    String fiscalYearId = UUID.randomUUID().toString();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(line).withFundDistribution(fundDistribution1).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
    FundDistribution fundDistribution2 = line.getFundDistribution().get(1);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution2).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
    FundDistribution fundDistribution3 = line.getFundDistribution().get(1);
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution3).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
    List<LedgerFiscalYearRolloverProgress> progresses = Collections.singletonList(success);
    List<ReEncumbranceHolder> holders = List.of(holder1, holder2, holder3);
    // LedgerFiscalYearRolloverErrorCollection is not empty. Expected "needReEncumber" = true
    doReturn(holders).when(spyReEncumbranceHoldersBuilder).buildReEncumbranceHoldersWithOrdersData(any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withFundsData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withCurrentFiscalYearData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withRollovers(any(), any());
    doReturn(completedFuture(progresses)).when(rolloverRetrieveService).getRolloversProgress(anyString(), any());
    doReturn(completedFuture(ledgerFiscalYearRolloverErrors)).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
    CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
    CompositePurchaseOrder compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
    assertTrue(compOrder.getNeedReEncumber());
    // LedgerFiscalYearRolloverErrorCollection is empty. Expected "needReEncumber" = false
    doReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection())).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
    compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
    assertFalse(compOrder.getNeedReEncumber());
    // LedgerFyRollover not exists. Expected "needReEncumber" = false
    doReturn(completedFuture(new LedgerFiscalYearRolloverCollection())).when(rolloverRetrieveService).getLedgerFyRollovers(anyString(), anyString(), any());
    compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
    assertFalse(compOrder.getNeedReEncumber());
}
Also used : LedgerFiscalYearRolloverErrorCollection(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) LedgerFiscalYearRolloverCollection(org.folio.rest.jaxrs.model.LedgerFiscalYearRolloverCollection) LedgerFiscalYearRolloverProgress(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverProgress) LedgerFiscalYearRolloverError(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverError) Test(org.junit.jupiter.api.Test)

Example 19 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class OrderRolloverServiceTest method shouldUpdateFundDistributionsAmountsBasedOnUpdatedEstimatedPrice.

@Test
@DisplayName("Should update FundDistributions amounts based on updatedEstimatedPrice")
void shouldUpdateFundDistributionsAmountsBasedOnUpdatedEstimatedPrice() {
    String fromFiscalYearId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    String toFiscalYearId = UUID.randomUUID().toString();
    String fundId1 = UUID.randomUUID().toString();
    String fundId2 = UUID.randomUUID().toString();
    String orderId1 = UUID.randomUUID().toString();
    String poLineId1 = UUID.randomUUID().toString();
    String prevEncumbrId1 = UUID.randomUUID().toString();
    String prevEncumbrId2 = UUID.randomUUID().toString();
    String currEncumbrId1 = UUID.randomUUID().toString();
    String expClassId2 = UUID.randomUUID().toString();
    EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
    EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
    EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
    LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
    List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId));
    PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    List<PurchaseOrder> orders = List.of(purchaseOrder1);
    PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(1);
    FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(50d).withDistributionType(DistributionType.PERCENTAGE).withEncumbrance(prevEncumbrId1);
    FundDistribution fundDistributionOngoing = new FundDistribution().withFundId(fundId2).withValue(297.5d).withDistributionType(DistributionType.AMOUNT).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
    Cost costOneTime = new Cost().withListUnitPrice(595d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(595d);
    PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime, fundDistributionOngoing));
    List<PoLine> poLines = List.of(poLineOneTime);
    doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
    doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
    Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(580d);
    Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
    List<Transaction> encumbrances = List.of(transactionOneTime);
    TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(1);
    doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
    double exchangeEurToUsdRate = 1.0d;
    doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
    String polCurrency = systemCurrency;
    ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
    ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
    ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
    ExchangeRate exchangeRate = mock(ExchangeRate.class);
    doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
    doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
    doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
    when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
    when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
    when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
    when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
    CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
    future.join();
    assertFalse(future.isCompletedExceptionally());
    assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
    assertThat(costOneTime.getPoLineEstimatedPrice(), equalTo(580d));
    assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(-15d));
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) DefaultNumberValue(org.javamoney.moneta.spi.DefaultNumberValue) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) ExchangeRate(javax.money.convert.ExchangeRate) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ManualExchangeRateProvider(org.folio.service.exchange.ManualExchangeRateProvider) Fund(org.folio.rest.acq.model.finance.Fund) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Cost(org.folio.rest.jaxrs.model.Cost) ManualCurrencyConversion(org.folio.service.exchange.ManualCurrencyConversion) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ConversionQuery(javax.money.convert.ConversionQuery) Transaction(org.folio.rest.acq.model.finance.Transaction) PoLine(org.folio.rest.jaxrs.model.PoLine) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 20 with Fund

use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.

the class FundService method getAllFundsByIds.

private CompletableFuture<List<Fund>> getAllFundsByIds(Collection<String> ids, RequestContext requestContext) {
    String query = convertIdsToCqlQuery(ids);
    RequestEntry requestEntry = new RequestEntry(ENDPOINT).withQuery(query).withLimit(MAX_IDS_FOR_GET_RQ).withOffset(0);
    return restClient.get(requestEntry, requestContext, FundCollection.class).thenApply(FundCollection::getFunds).thenApply(funds -> {
        if (funds.size() == ids.size()) {
            return funds;
        }
        List<Parameter> parameters = ids.stream().filter(id -> funds.stream().noneMatch(fund -> fund.getId().equals(id))).map(id -> new Parameter().withValue(id).withKey("funds")).collect(Collectors.toList());
        throw new HttpException(404, FUNDS_NOT_FOUND.toError().withParameters(parameters));
    });
}
Also used : RestClient(org.folio.rest.core.RestClient) FUNDS_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.FUNDS_NOT_FOUND) Collection(java.util.Collection) HelperUtils(org.folio.orders.utils.HelperUtils) HttpException(org.folio.rest.core.exceptions.HttpException) RequestEntry(org.folio.rest.core.models.RequestEntry) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) Fund(org.folio.rest.acq.model.finance.Fund) Collectors(java.util.stream.Collectors) StreamEx.ofSubLists(one.util.streamex.StreamEx.ofSubLists) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) List(java.util.List) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) RequestContext(org.folio.rest.core.models.RequestContext) FundCollection(org.folio.rest.acq.model.finance.FundCollection) Parameter(org.folio.rest.jaxrs.model.Parameter) Collections(java.util.Collections) Parameter(org.folio.rest.jaxrs.model.Parameter) HttpException(org.folio.rest.core.exceptions.HttpException) RequestEntry(org.folio.rest.core.models.RequestEntry)

Aggregations

Fund (org.folio.rest.acq.model.finance.Fund)47 Test (org.junit.jupiter.api.Test)39 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)17 Budget (org.folio.rest.acq.model.finance.Budget)15 ArrayList (java.util.ArrayList)14 Transaction (org.folio.rest.acq.model.finance.Transaction)12 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)11 FundCollection (org.folio.rest.acq.model.finance.FundCollection)11 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)10 Invoice (org.folio.rest.jaxrs.model.Invoice)10 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)9 Error (org.folio.rest.jaxrs.model.Error)9 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 List (java.util.List)8 Headers (io.restassured.http.Headers)7 HttpException (org.folio.invoices.rest.exceptions.HttpException)7 JsonObject (io.vertx.core.json.JsonObject)6 Ledger (org.folio.rest.acq.model.finance.Ledger)6 ConversionQuery (javax.money.convert.ConversionQuery)5