Search in sources :

Example 26 with Budget

use of org.folio.rest.acq.model.finance.Budget 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

Budget (org.folio.rest.acq.model.finance.Budget)26 Test (org.junit.jupiter.api.Test)19 ArrayList (java.util.ArrayList)17 Fund (org.folio.rest.acq.model.finance.Fund)14 Transaction (org.folio.rest.acq.model.finance.Transaction)12 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)10 InvoiceWorkflowDataHolder (org.folio.models.InvoiceWorkflowDataHolder)9 EncumbranceRelationsHolder (org.folio.models.EncumbranceRelationsHolder)8 FiscalYear (org.folio.rest.acq.model.finance.FiscalYear)7 Error (org.folio.rest.jaxrs.model.Error)7 List (java.util.List)6 HttpException (org.folio.invoices.rest.exceptions.HttpException)6 JsonObject (io.vertx.core.json.JsonObject)4 Collections (java.util.Collections)4 Collectors.toList (java.util.stream.Collectors.toList)4 BudgetCollection (org.folio.rest.acq.model.finance.BudgetCollection)4 Ledger (org.folio.rest.acq.model.finance.Ledger)4 Invoice (org.folio.rest.jaxrs.model.Invoice)4 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)4 HttpException (org.folio.rest.core.exceptions.HttpException)3