Search in sources :

Example 21 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountGreaterThanBudgetRemainingAmountAndBudgetRestricted.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountGreaterThanBudgetRemainingAmountAndBudgetRestricted() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    String fundCode = "TEST-FUND";
    Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(10d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50d).withAllowableEncumbrance(100d);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    FundDistribution fundDistribution = new FundDistribution().withFundId(fundId).withCode(fundCode);
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(null).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(true).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD").withFundDistribution(fundDistribution);
    holders.add(holder);
    HttpException httpException = assertThrows(HttpException.class, () -> restrictionService.checkEncumbranceRestrictions(holders));
    assertEquals(422, httpException.getCode());
    Error error = httpException.getError();
    assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
    assertEquals(Collections.singletonList(fundCode).toString(), error.getParameters().get(0).getValue());
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.rest.core.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Example 22 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndRestrictEncumbranceIsFalse.

@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndRestrictEncumbranceIsFalse() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    Transaction existingTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(50d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Transaction newTransaction = new Transaction().withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withAmount(60d).withFiscalYearId(fiscalYearId).withFromFundId(fundId).withCurrency("USD");
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(59d).withTotalFunding(59d).withAvailable(0d).withUnavailable(50d).withAwaitingPayment(50d).withAllowableEncumbrance(100d);
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(false).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
    holders.add(holder);
    assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Budget(org.folio.rest.acq.model.finance.Budget) Test(org.junit.jupiter.api.Test)

Example 23 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulatePoLineToFiscalYearCurrencyConversion.

@Test
void testShouldPopulatePoLineToFiscalYearCurrencyConversion() {
    // given
    String currency = "RUB";
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    holders.add(holder1.withCurrency(currency));
    holders.add(holder2.withCurrency(currency));
    holders.add(holder3.withCurrency(currency));
    ExchangeRateProvider exchangeRateProvider = mock(ManualExchangeRateProvider.class);
    when(exchangeRateProviderResolver.resolve(any(), any())).thenReturn(exchangeRateProvider);
    when(exchangeRateProvider.getCurrencyConversion(any(ConversionQuery.class))).thenAnswer(invocation -> {
        ConversionQuery conversionQuery = invocation.getArgument(0);
        return mock(ManualCurrencyConversion.class, conversionQuery.getBaseCurrency().getCurrencyCode());
    });
    when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
    // When
    encumbranceRelationsHoldersBuilder.withConversion(holders, requestContextMock).join();
    // Then
    assertEquals("USD", holder1.getPoLineToFyConversion().toString());
    assertEquals("USD", holder2.getPoLineToFyConversion().toString());
    assertSame(holder1.getPoLineToFyConversion(), holder2.getPoLineToFyConversion());
    assertEquals("EUR", holder3.getPoLineToFyConversion().toString());
}
Also used : ConversionQuery(javax.money.convert.ConversionQuery) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ManualExchangeRateProvider(org.folio.service.exchange.ManualExchangeRateProvider) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 24 with EncumbranceRelationsHolder

use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.

the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithOldEncumbranceIfMatchesTransactionFromStorage.

@Test
void testShouldPopulateHoldersWithOldEncumbranceIfMatchesTransactionFromStorage() {
    // given
    Transaction encumbranceFromStorage = new Transaction().withId(UUID.randomUUID().toString()).withFromFundId(distribution1.getFundId()).withSource(PO_LINE).withAmount(38d).withFiscalYearId(UUID.randomUUID().toString()).withEncumbrance(new Encumbrance().withSubscription(false).withReEncumber(true).withOrderType(ONGOING).withSourcePurchaseOrderId(order.getId()).withSourcePoLineId(line1.getId()).withInitialAmountEncumbered(68d).withAmountExpended(10d).withAmountAwaitingPayment(20d));
    List<EncumbranceRelationsHolder> holders = new ArrayList<>();
    holders.add(holder1);
    holders.add(holder2);
    when(encumbranceService.getEncumbrancesByIds(anyList(), any())).thenReturn(CompletableFuture.completedFuture(singletonList(encumbranceFromStorage)));
    // When
    List<EncumbranceRelationsHolder> resultHolders = encumbranceRelationsHoldersBuilder.withExistingTransactions(holders, order, requestContextMock).join();
    // Then
    assertThat(resultHolders, hasSize(2));
    assertEquals(encumbranceFromStorage, holder1.getOldEncumbrance());
    assertEquals(encumbranceFromStorage.getId(), holder1.getNewEncumbrance().getId());
    assertEquals(encumbranceFromStorage.getEncumbrance().getAmountExpended(), holder1.getNewEncumbrance().getEncumbrance().getAmountExpended());
    assertEquals(encumbranceFromStorage.getEncumbrance().getAmountAwaitingPayment(), holder1.getNewEncumbrance().getEncumbrance().getAmountAwaitingPayment());
    assertNull(holder2.getOldEncumbrance());
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

EncumbranceRelationsHolder (org.folio.models.EncumbranceRelationsHolder)24 Transaction (org.folio.rest.acq.model.finance.Transaction)18 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)13 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)12 Budget (org.folio.rest.acq.model.finance.Budget)11 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)10 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)9 Objects (java.util.Objects)8 List (java.util.List)7 MonetaryAmount (javax.money.MonetaryAmount)7 Map (java.util.Map)6 CurrencyConversion (javax.money.convert.CurrencyConversion)6 Cost (org.folio.rest.jaxrs.model.Cost)6 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 Collectors.toList (java.util.stream.Collectors.toList)5 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)5 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)4 Fund (org.folio.rest.acq.model.finance.Fund)4