use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class EncumbranceRelationsHoldersBuilderTest method testShouldPopulateHoldersWithFiscalYearData.
@Test
void testShouldPopulateHoldersWithFiscalYearData() {
// given
String fiscalYearId = UUID.randomUUID().toString();
FiscalYear fiscalYear = new FiscalYear().withId(fiscalYearId).withCurrency("RUB");
Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder1.getFundId()).withFiscalYearId(fiscalYearId);
Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder2.getFundId()).withFiscalYearId(fiscalYearId);
Budget budget3 = new Budget().withId(UUID.randomUUID().toString()).withFundId(holder3.getFundId()).withFiscalYearId(fiscalYearId);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
holders.add(holder1.withBudget(budget1));
holders.add(holder2.withBudget(budget2));
holders.add(holder3.withBudget(budget3));
when(fiscalYearService.getFiscalYearById(anyString(), any())).thenReturn(CompletableFuture.completedFuture(fiscalYear));
// When
List<EncumbranceRelationsHolder> resultHolders = encumbranceRelationsHoldersBuilder.withFiscalYearData(holders, requestContextMock).join();
// Then
assertThat(resultHolders, everyItem(hasProperty("newEncumbrance", allOf(hasProperty("fiscalYearId", is(fiscalYear.getId())), hasProperty("currency", is(fiscalYear.getCurrency()))))));
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceGreaterThanBudgetRemainingAmountAndBudgetAllowableExpenditureIsNull() {
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(null);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withRestrictEncumbrances(true).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
holders.add(holder);
assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class BudgetRestrictionServiceTest method checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount.
@Test
void checkEnoughMoneyInBudgetShouldPassIfTransactionsAmountDifferenceLessThanBudgetRemainingAmount() {
String fiscalYearId = UUID.randomUUID().toString();
String fundId = UUID.randomUUID().toString();
String ledgerId = 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).withAvailable(9d).withTotalFunding(59d).withUnavailable(50d).withAwaitingPayment(50D).withAllowableEncumbrance(150d);
Fund fund = new Fund().withId(fundId).withLedgerId(ledgerId);
Ledger ledger = new Ledger().withId(ledgerId).withRestrictEncumbrance(true);
List<EncumbranceRelationsHolder> holders = new ArrayList<>();
EncumbranceRelationsHolder holder = new EncumbranceRelationsHolder().withOldEncumbrance(existingTransaction).withNewEncumbrance(newTransaction).withBudget(budget).withLedgerId(fund.getLedgerId()).withRestrictEncumbrances(ledger.getRestrictExpenditures()).withCurrentFiscalYearId(fiscalYearId).withCurrency("USD");
holders.add(holder);
assertDoesNotThrow(() -> restrictionService.checkEncumbranceRestrictions(holders));
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class PendingToPendingEncumbranceStrategy method distributeHoldersByOperation.
private EncumbrancesProcessingHolder distributeHoldersByOperation(List<EncumbranceRelationsHolder> encumbranceRelationsHolders) {
EncumbrancesProcessingHolder holder = new EncumbrancesProcessingHolder();
holder.withEncumbrancesFromStorage(encumbranceRelationsHolders.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).filter(Objects::nonNull).collect(toList()));
List<EncumbranceRelationsHolder> toDelete = getTransactionsToDelete(encumbranceRelationsHolders);
List<Transaction> toRelease = toDelete.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).collect(toList());
holder.withEncumbrancesForRelease(toRelease);
holder.withEncumbrancesForDelete(toDelete);
return holder;
}
use of org.folio.models.EncumbranceRelationsHolder in project mod-orders by folio-org.
the class EncumbrancesProcessingHolderBuilder method distributeHoldersByOperation.
protected EncumbrancesProcessingHolder distributeHoldersByOperation(List<EncumbranceRelationsHolder> encumbranceRelationsHolders) {
EncumbrancesProcessingHolder holder = new EncumbrancesProcessingHolder();
holder.withEncumbrancesForCreate(getToBeCreatedHolders(encumbranceRelationsHolders));
holder.withEncumbrancesForUpdate(getToBeUpdatedHolders(encumbranceRelationsHolders));
List<EncumbranceRelationsHolder> toDelete = getTransactionsToDelete(encumbranceRelationsHolders);
holder.withEncumbrancesForDelete(toDelete);
// also release transaction before delete
List<Transaction> toRelease = toDelete.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).collect(toList());
holder.withEncumbrancesForRelease(toRelease);
holder.withEncumbrancesFromStorage(encumbranceRelationsHolders.stream().map(EncumbranceRelationsHolder::getOldEncumbrance).filter(Objects::nonNull).collect(toList()));
return holder;
}
Aggregations