Search in sources :

Example 26 with FiscalYear

use of org.folio.rest.acq.model.finance.FiscalYear in project mod-invoice by folio-org.

the class FundAvailabilityHolderValidatorTest method shouldCountAdjustmentsFundDistributionsDuringBudgetRemainingAmountValidation.

@Test
void shouldCountAdjustmentsFundDistributionsDuringBudgetRemainingAmountValidation() {
    String fiscalYearId = UUID.randomUUID().toString();
    String fundId = UUID.randomUUID().toString();
    String budgetId = UUID.randomUUID().toString();
    String ledgerId = UUID.randomUUID().toString();
    FiscalYear fiscalYear = new FiscalYear().withCurrency("USD").withId(fiscalYearId);
    Fund fund = new Fund().withId(fundId).withName("TestFund").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
    Budget budget = new Budget().withId(budgetId).withFiscalYearId(fiscalYearId).withFundId(fundId).withAllocated(260d).withTotalFunding(260d).withAvailable(210d).withUnavailable(50d).withAwaitingPayment(50d).withAllowableExpenditure(100d);
    List<InvoiceWorkflowDataHolder> holders = new ArrayList<>();
    Transaction adjustmentPendingPayment = new Transaction().withAmount(20d).withCurrency("USD");
    Transaction linePendingPayment = new Transaction().withAmount(200d).withCurrency("USD");
    InvoiceWorkflowDataHolder holder1 = new InvoiceWorkflowDataHolder().withFund(fund).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(fiscalYear).withNewTransaction(linePendingPayment);
    InvoiceWorkflowDataHolder holder2 = new InvoiceWorkflowDataHolder().withFund(fund).withBudget(budget).withRestrictExpenditures(true).withFiscalYear(fiscalYear).withNewTransaction(adjustmentPendingPayment);
    holders.add(holder1);
    holders.add(holder2);
    HttpException httpException = assertThrows(HttpException.class, () -> fundAvailabilityValidator.validate(holders));
    assertEquals(422, httpException.getCode());
    Error error = httpException.getErrors().getErrors().get(0);
    assertEquals(FUND_CANNOT_BE_PAID.getCode(), error.getCode());
    assertEquals(Collections.singletonList("FC").toString(), error.getParameters().get(0).getValue());
}
Also used : FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Fund(org.folio.rest.acq.model.finance.Fund) Transaction(org.folio.rest.acq.model.finance.Transaction) InvoiceWorkflowDataHolder(org.folio.models.InvoiceWorkflowDataHolder) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) Budget(org.folio.rest.acq.model.finance.Budget) HttpException(org.folio.invoices.rest.exceptions.HttpException) Test(org.junit.jupiter.api.Test)

Aggregations

FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)26 Test (org.junit.jupiter.api.Test)22 Fund (org.folio.rest.acq.model.finance.Fund)11 ArrayList (java.util.ArrayList)9 Transaction (org.folio.rest.acq.model.finance.Transaction)9 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)7 Budget (org.folio.rest.acq.model.finance.Budget)7 HttpException (org.folio.invoices.rest.exceptions.HttpException)4 CompositeOrderRetrieveHolder (org.folio.models.CompositeOrderRetrieveHolder)4 ReEncumbranceHolder (org.folio.models.ReEncumbranceHolder)4 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)4 Error (org.folio.rest.jaxrs.model.Error)4 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)3 HttpException (org.folio.rest.core.exceptions.HttpException)3 JsonObject (io.vertx.core.json.JsonObject)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2