Search in sources :

Example 26 with Fund

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

the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithCorrespondingLedgerData.

@Test
void testShouldPopulateHoldersWithCorrespondingLedgerData() {
    // given
    Fund fund1 = new Fund().withId(holder1.getFundId()).withLedgerId(UUID.randomUUID().toString());
    Fund fund2 = new Fund().withId(holder2.getFundId()).withLedgerId(UUID.randomUUID().toString());
    Fund fund3 = new Fund().withId(holder3.getFundId()).withLedgerId(UUID.randomUUID().toString());
    Ledger ledger1 = new Ledger().withId(fund1.getLedgerId()).withRestrictEncumbrance(true);
    Ledger ledger2 = new Ledger().withId(fund2.getLedgerId()).withRestrictEncumbrance(true);
    Ledger ledger3 = new Ledger().withId(fund3.getLedgerId()).withRestrictEncumbrance(false);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    holders.add(holder1);
    holders.add(holder2);
    holders.add(holder3);
    when(fundService.getAllFunds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(List.of(fund1, fund2, fund3)));
    when(ledgerService.getLedgersByIds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(List.of(ledger2, ledger1, ledger3)));
    // When
    encumbranceRelationsHoldersBuilder.withLedgersData(holders, requestContextMock).join();
    // Then
    assertEquals(ledger1.getId(), holder1.getLedgerId());
    assertEquals(ledger1.getRestrictEncumbrance(), holder1.getRestrictEncumbrance());
    assertEquals(ledger2.getId(), holder2.getLedgerId());
    assertEquals(ledger2.getRestrictEncumbrance(), holder2.getRestrictEncumbrance());
    assertEquals(ledger3.getId(), holder3.getLedgerId());
    assertEquals(ledger3.getRestrictEncumbrance(), holder3.getRestrictEncumbrance());
}
Also used : Fund(org.folio.rest.acq.model.finance.Fund) Ledger(org.folio.rest.acq.model.finance.Ledger) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 27 with Fund

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

the class OrderReEncumberServiceTest method shouldVerifyFYROAdjustmentAndFundDistributionValuesWhenMixedFunds.

@Test
void shouldVerifyFYROAdjustmentAndFundDistributionValuesWhenMixedFunds() {
    String ledgerId = UUID.randomUUID().toString();
    String fromFyId = UUID.randomUUID().toString();
    String toFyId = UUID.randomUUID().toString();
    String orderId = UUID.randomUUID().toString();
    String fund1Id = UUID.randomUUID().toString();
    String fund2Id = UUID.randomUUID().toString();
    String rolloverId = UUID.randomUUID().toString();
    Ledger notRestrictedLedger = new Ledger().withId(ledgerId).withRestrictEncumbrance(false);
    double exchangeRate = 1.1d;
    Fund fund1 = new Fund().withId(fund1Id).withLedgerId(ledgerId);
    Fund fund2 = new Fund().withId(fund2Id).withLedgerId(ledgerId);
    Budget notRestrictedBudget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund1Id);
    EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(10d);
    LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withId(rolloverId).withLedgerId(ledgerId).withFromFiscalYearId(fromFyId).withToFiscalYearId(toFyId).withEncumbrancesRollover(Collections.singletonList(encumbranceRollover));
    CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(orderId).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
    Cost cost1 = new Cost().withListUnitPrice(120d).withQuantityPhysical(1).withExchangeRate(exchangeRate).withCurrency("EUR").withPoLineEstimatedPrice(120d);
    Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(40d)).withAmount(20d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(30d)).withAmount(30d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction toEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withStatus(Encumbrance.Status.UNRELEASED).withAmountAwaitingPayment(0d).withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(0d)).withAmount(40d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    Transaction toEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withStatus(Encumbrance.Status.UNRELEASED).withAmountAwaitingPayment(0d).withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(0d)).withAmount(30d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
    TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.EMPTY_LIST).withTotalRecords(0);
    FundDistribution fundDistribution1 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(50d).withEncumbrance(fromEncumbrance1.getId()).withFundId(fund1Id);
    FundDistribution fundDistribution2 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.AMOUNT).withValue(60d).withEncumbrance(fromEncumbrance2.getId()).withFundId(fund2Id);
    CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withCost(cost1).withFundDistribution(List.of(fundDistribution1, fundDistribution2));
    ConversionQuery conversionPoLineToFyQuery = ConversionQueryBuilder.of().setBaseCurrency("EUR").setTermCurrency("USD").set(ExchangeRateProviderResolver.RATE_KEY, exchangeRate).build();
    ConversionQuery conversionFyToPoLineQuery = ConversionQueryBuilder.of().setBaseCurrency("USD").setTermCurrency("EUR").set(ExchangeRateProviderResolver.RATE_KEY, exchangeRate).build();
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withLedgerId(ledgerId).withRestrictEncumbrances(notRestrictedLedger.getRestrictEncumbrance()).withBudget(notRestrictedBudget1).withEncumbranceRollover(encumbranceRollover).withPreviousFyEncumbrance(fromEncumbrance1).withNewEncumbrance(toEncumbrance1).withPoLineToFyConversion(exchangeRateProvider.getCurrencyConversion(conversionPoLineToFyQuery)).withFyToPoLineConversion(exchangeRateProvider.getCurrencyConversion(conversionFyToPoLineQuery));
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution2).withLedgerId(ledgerId).withRestrictEncumbrances(notRestrictedLedger.getRestrictEncumbrance()).withBudget(notRestrictedBudget1).withEncumbranceRollover(encumbranceRollover).withNewEncumbrance(toEncumbrance2).withPreviousFyEncumbrance(fromEncumbrance2).withPoLineToFyConversion(exchangeRateProvider.getCurrencyConversion(conversionPoLineToFyQuery)).withFyToPoLineConversion(exchangeRateProvider.getCurrencyConversion(conversionFyToPoLineQuery));
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    when(purchaseOrderStorageService.getCompositeOrderById(anyString(), eq(requestContext))).thenAnswer(invocation -> completedFuture(new CompositePurchaseOrder().withId(invocation.getArgument(0))));
    doReturn(holders).when(spyReEncumbranceHoldersBuilder).buildReEncumbranceHoldersWithOrdersData(any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withFundsData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withLedgersData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withCurrentFiscalYearData(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withRollovers(any(), any());
    doReturn(holders).when(spyReEncumbranceHoldersBuilder).withEncumbranceRollover(any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withBudgets(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withConversions(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withPreviousFyEncumbrances(any(), any());
    doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withToEncumbrances(any(), any());
    doNothing().when(budgetRestrictionService).checkEncumbranceRestrictions(anyList());
    when(rolloverErrorService.getLedgerFyRolloverErrors(anyString(), any())).thenReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection()));
    when(rolloverErrorService.deleteRolloverErrors(anyList(), any())).thenReturn(completedFuture(null));
    when(purchaseOrderLineService.saveOrderLines(anyList(), any())).thenReturn(completedFuture(null));
    when(rolloverRetrieveService.getRolloversProgress(eq(rolloverId), any())).thenReturn(completedFuture(Collections.singletonList(success)));
    when(exchangeRateProviderResolver.resolve(conversionPoLineToFyQuery, requestContext)).thenReturn(exchangeRateProvider);
    when(exchangeRateProviderResolver.resolve(conversionFyToPoLineQuery, requestContext)).thenReturn(exchangeRateProvider);
    when(transactionService.getTransactions(anyString(), eq(0), eq(Integer.MAX_VALUE), eq(requestContext))).thenReturn(completedFuture(toTransactionCollection));
    when(transactionSummaryService.updateOrderTransactionSummary(eq(orderId), anyInt(), eq(requestContext))).thenReturn(completedFuture(null));
    when(transactionService.createTransaction(any(), eq(requestContext))).thenReturn(completedFuture(new Transaction()));
    // When
    CompletableFuture<Void> future = orderReEncumberService.reEncumber(UUID.randomUUID().toString(), requestContext);
    future.join();
    // Then
    assertFalse(future.isCompletedExceptionally());
    assertEquals(-35.3d, line1.getCost().getFyroAdjustmentAmount());
    assertEquals(50d, line1.getFundDistribution().get(0).getValue());
    assertEquals(42.35d, line1.getFundDistribution().get(1).getValue());
}
Also used : EncumbranceRollover(org.folio.rest.jaxrs.model.EncumbranceRollover) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) LedgerFiscalYearRolloverErrorCollection(org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection) Fund(org.folio.rest.acq.model.finance.Fund) Ledger(org.folio.rest.acq.model.finance.Ledger) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ConversionQuery(javax.money.convert.ConversionQuery) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 28 with Fund

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateEachReEncumbranceHolderWithCorrespondingLedgerIdIfAllFundsFound.

@Test
void shouldPopulateEachReEncumbranceHolderWithCorrespondingLedgerIdIfAllFundsFound() {
    FundDistribution fundDistribution1 = new FundDistribution().withFundId(UUID.randomUUID().toString());
    FundDistribution fundDistribution2 = new FundDistribution().withFundId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withFundDistribution(fundDistribution1);
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withFundDistribution(fundDistribution2);
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    Fund fund1 = new Fund().withId(fundDistribution1.getFundId()).withLedgerId(UUID.randomUUID().toString());
    Fund fund2 = new Fund().withId(fundDistribution2.getFundId()).withLedgerId(UUID.randomUUID().toString());
    when(fundService.getFunds(anyCollection(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(fund2, fund1)));
    reEncumbranceHoldersBuilder.withFundsData(holders, requestContext).join();
    assertEquals(fund1.getLedgerId(), holder1.getLedgerId());
    assertEquals(fund2.getLedgerId(), holder2.getLedgerId());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 29 with Fund

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateEachReEncumbranceHolderWithFiscalYearIfFundExist.

@Test
void shouldPopulateEachReEncumbranceHolderWithFiscalYearIfFundExist() {
    Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
    FiscalYear fiscalYear = new FiscalYear().withId(UUID.randomUUID().toString());
    when(fiscalYearService.getCurrentFiscalYear(anyString(), any())).thenReturn(CompletableFuture.completedFuture(fiscalYear));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withCurrentFiscalYearData(holders, requestContext).join();
    assertThat(resultHolders, everyItem(hasProperty("currentFiscalYearId", is(fiscalYear.getId()))));
    assertThat(resultHolders, everyItem(hasProperty("currency", is(fiscalYear.getCurrency()))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) Test(org.junit.jupiter.api.Test)

Example 30 with Fund

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

the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingRollover.

@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingRollover() {
    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());
    FiscalYear currentFiscalYear = new FiscalYear().withId(UUID.randomUUID().toString());
    ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
    ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
    ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
    ReEncumbranceHolder holder4 = new ReEncumbranceHolder().withLedgerId(fund4.getLedgerId()).withCurrentFiscalYearId(currentFiscalYear.getId());
    List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3, holder4);
    LedgerFiscalYearRollover rollover1 = new LedgerFiscalYearRollover().withLedgerId(ledgerId1);
    LedgerFiscalYearRollover rollover2 = new LedgerFiscalYearRollover().withLedgerId(ledgerId2);
    when(rolloverRetrieveService.getLedgerFyRollovers(anyString(), anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(rollover1, rollover2)));
    List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", is(rollover2)), hasProperty("ledgerId", is(fund3.getLedgerId())))));
    assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund4.getLedgerId())))));
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) ReEncumbranceHolder(org.folio.models.ReEncumbranceHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Test(org.junit.jupiter.api.Test)

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