use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId.
@Test
void shouldPopulateReEncumbranceHoldersWithCorrespondingBudgetsForEveryHolderWithLedgerId() {
Fund fund1 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
Fund fund2 = new Fund().withId(UUID.randomUUID().toString()).withLedgerId(UUID.randomUUID().toString());
FundDistribution distribution1 = new FundDistribution().withFundId(fund1.getId());
FundDistribution distribution2 = new FundDistribution().withFundId(fund2.getId());
FundDistribution distribution3 = new FundDistribution().withFundId(UUID.randomUUID().toString());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId()).withFundDistribution(distribution1);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId()).withFundDistribution(distribution2);
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withFundDistribution(distribution3);
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3);
Budget budget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund1.getId());
Budget budget2 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund2.getId());
when(budgetService.fetchBudgetsByFundIds(anyList(), any())).thenReturn(CompletableFuture.completedFuture(Arrays.asList(budget1, budget2)));
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withBudgets(holders, requestContext).join();
assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget1)), hasProperty("ledgerId", is(fund1.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("budget", is(budget2)), hasProperty("ledgerId", is(fund2.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("budget", nullValue()), hasProperty("ledgerId", nullValue()))));
}
use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.
the class ReEncumbranceHoldersBuilderTest method shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFiscalYearNull.
@Test
void shouldNotRetrieveRolloversIfReEncumbranceHoldersCurrentFiscalYearNull() {
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());
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withLedgerId(fund1.getLedgerId());
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withLedgerId(fund2.getLedgerId());
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withLedgerId(fund3.getLedgerId());
ReEncumbranceHolder holder4 = new ReEncumbranceHolder().withLedgerId(fund4.getLedgerId());
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2, holder3, holder4);
List<ReEncumbranceHolder> resultHolders = reEncumbranceHoldersBuilder.withRollovers(holders, requestContext).join();
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund1.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund2.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund3.getLedgerId())))));
assertThat(resultHolders, hasItem(allOf(hasProperty("rollover", nullValue()), hasProperty("ledgerId", is(fund4.getLedgerId())))));
verify(rolloverRetrieveService, never()).getLedgerFyRollovers(anyString(), anyList(), any());
}
use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.
the class OrderReEncumberServiceTest method testPopulateNeedReEncumberField.
@Test
void testPopulateNeedReEncumberField() {
// given
CompositePurchaseOrder order = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
String ledgerId = UUID.randomUUID().toString();
Fund sampleFund = new Fund().withLedgerId(UUID.randomUUID().toString()).withFundStatus(Fund.FundStatus.ACTIVE).withCode(UUID.randomUUID().toString());
LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withLedgerId(ledgerId);
LedgerFiscalYearRolloverErrorCollection ledgerFiscalYearRolloverErrors = new LedgerFiscalYearRolloverErrorCollection().withLedgerFiscalYearRolloverErrors(Collections.singletonList(new LedgerFiscalYearRolloverError()));
CompositePoLine line = order.getCompositePoLines().get(0);
FundDistribution fundDistribution1 = line.getFundDistribution().get(0);
String fiscalYearId = UUID.randomUUID().toString();
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(line).withFundDistribution(fundDistribution1).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
FundDistribution fundDistribution2 = line.getFundDistribution().get(1);
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution2).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
FundDistribution fundDistribution3 = line.getFundDistribution().get(1);
ReEncumbranceHolder holder3 = new ReEncumbranceHolder().withPurchaseOrder(order).withPoLine(order.getCompositePoLines().get(0)).withFundDistribution(fundDistribution3).withRollover(rollover).withLedgerId(ledgerId).withCurrentFiscalYearId(fiscalYearId);
List<LedgerFiscalYearRolloverProgress> progresses = Collections.singletonList(success);
List<ReEncumbranceHolder> holders = List.of(holder1, holder2, holder3);
// LedgerFiscalYearRolloverErrorCollection is not empty. Expected "needReEncumber" = true
doReturn(holders).when(spyReEncumbranceHoldersBuilder).buildReEncumbranceHoldersWithOrdersData(any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withFundsData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withCurrentFiscalYearData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withRollovers(any(), any());
doReturn(completedFuture(progresses)).when(rolloverRetrieveService).getRolloversProgress(anyString(), any());
doReturn(completedFuture(ledgerFiscalYearRolloverErrors)).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
CompositeOrderRetrieveHolder holder = new CompositeOrderRetrieveHolder(order);
CompositePurchaseOrder compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
assertTrue(compOrder.getNeedReEncumber());
// LedgerFiscalYearRolloverErrorCollection is empty. Expected "needReEncumber" = false
doReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection())).when(rolloverErrorService).getLedgerFyRolloverErrors(any(), any());
compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
assertFalse(compOrder.getNeedReEncumber());
// LedgerFyRollover not exists. Expected "needReEncumber" = false
doReturn(completedFuture(new LedgerFiscalYearRolloverCollection())).when(rolloverRetrieveService).getLedgerFyRollovers(anyString(), anyString(), any());
compOrder = orderReEncumberService.populate(holder, requestContext).join().getOrder();
assertFalse(compOrder.getNeedReEncumber());
}
use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.
the class OrderRolloverServiceTest method shouldUpdateFundDistributionsAmountsBasedOnUpdatedEstimatedPrice.
@Test
@DisplayName("Should update FundDistributions amounts based on updatedEstimatedPrice")
void shouldUpdateFundDistributionsAmountsBasedOnUpdatedEstimatedPrice() {
String fromFiscalYearId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
String toFiscalYearId = UUID.randomUUID().toString();
String fundId1 = UUID.randomUUID().toString();
String fundId2 = UUID.randomUUID().toString();
String orderId1 = UUID.randomUUID().toString();
String poLineId1 = UUID.randomUUID().toString();
String prevEncumbrId1 = UUID.randomUUID().toString();
String prevEncumbrId2 = UUID.randomUUID().toString();
String currEncumbrId1 = UUID.randomUUID().toString();
String expClassId2 = UUID.randomUUID().toString();
EncumbranceRollover ongoingEncumbranceBasedOnExpended = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.EXPENDED);
EncumbranceRollover oneTimeEncumbrance = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withBasedOn(EncumbranceRollover.BasedOn.REMAINING);
EncumbranceRollover ongoingEncumbranceBasedOnInitialAmount = new EncumbranceRollover().withOrderType(EncumbranceRollover.OrderType.ONGOING).withBasedOn(EncumbranceRollover.BasedOn.INITIAL_AMOUNT);
LedgerFiscalYearRollover ledgerFiscalYearRollover = new LedgerFiscalYearRollover().withId(UUID.randomUUID().toString()).withFromFiscalYearId(fromFiscalYearId).withLedgerId(ledgerId).withToFiscalYearId(toFiscalYearId).withEncumbrancesRollover(List.of(ongoingEncumbranceBasedOnExpended, oneTimeEncumbrance, ongoingEncumbranceBasedOnInitialAmount));
List<Fund> funds = List.of(new Fund().withId(fundId1).withLedgerId(ledgerId), new Fund().withId(fundId2).withLedgerId(ledgerId));
PurchaseOrder purchaseOrder1 = new PurchaseOrder().withId(orderId1).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
List<PurchaseOrder> orders = List.of(purchaseOrder1);
PurchaseOrderCollection purchaseOrderCollection = new PurchaseOrderCollection().withPurchaseOrders(orders).withTotalRecords(1);
FundDistribution fundDistributionOneTime = new FundDistribution().withFundId(fundId1).withValue(50d).withDistributionType(DistributionType.PERCENTAGE).withEncumbrance(prevEncumbrId1);
FundDistribution fundDistributionOngoing = new FundDistribution().withFundId(fundId2).withValue(297.5d).withDistributionType(DistributionType.AMOUNT).withEncumbrance(prevEncumbrId2).withExpenseClassId(expClassId2);
Cost costOneTime = new Cost().withListUnitPrice(595d).withQuantityPhysical(1).withCurrency("USD").withPoLineEstimatedPrice(595d);
PoLine poLineOneTime = new PoLine().withId(poLineId1).withPurchaseOrderId(orderId1).withCost(costOneTime).withFundDistribution(List.of(fundDistributionOneTime, fundDistributionOngoing));
List<PoLine> poLines = List.of(poLineOneTime);
doReturn(completedFuture(funds)).when(fundService).getFundsByLedgerId(ledgerId, requestContext);
doReturn(completedFuture(purchaseOrderCollection)).when(purchaseOrderStorageService).getPurchaseOrders(anyString(), anyInt(), anyInt(), any());
doReturn(completedFuture(poLines)).when(purchaseOrderLineService).getOrderLines(anyString(), anyInt(), anyInt(), any());
doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLines(eq(poLines), any());
Encumbrance encumbranceOneTime = new Encumbrance().withSourcePurchaseOrderId(orderId1).withSourcePoLineId(poLineId1).withOrderType(Encumbrance.OrderType.ONE_TIME).withInitialAmountEncumbered(580d);
Transaction transactionOneTime = new Transaction().withId(currEncumbrId1).withFromFundId(fundId1).withEncumbrance(encumbranceOneTime);
List<Transaction> encumbrances = List.of(transactionOneTime);
TransactionCollection encumbranceCollection = new TransactionCollection().withTransactions(encumbrances).withTotalRecords(1);
doReturn(completedFuture(encumbranceCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), any());
double exchangeEurToUsdRate = 1.0d;
doReturn(completedFuture(systemCurrency)).when(configurationEntriesService).getSystemCurrency(requestContext);
String polCurrency = systemCurrency;
ConversionQuery actQuery = ConversionQueryBuilder.of().setBaseCurrency(polCurrency).setTermCurrency(systemCurrency).set(RATE_KEY, exchangeEurToUsdRate).build();
ExchangeRateProvider exchangeRateProvider = Mockito.mock(ManualExchangeRateProvider.class);
ManualCurrencyConversion manualCurrencyConversion = new ManualCurrencyConversion(actQuery, exchangeRateProvider, ConversionContext.of());
ExchangeRate exchangeRate = mock(ExchangeRate.class);
doReturn(exchangeRateProvider).when(exchangeRateProviderResolver).resolve(any(ConversionQuery.class), eq(requestContext));
doReturn(manualCurrencyConversion).when(exchangeRateProvider).getCurrencyConversion(any(ConversionQuery.class));
doReturn(exchangeRate).when(exchangeRateProvider).getExchangeRate(any(ConversionQuery.class));
when(exchangeRate.getContext()).thenReturn(ConversionContext.of());
when(exchangeRate.getCurrency()).thenReturn(Monetary.getCurrency(systemCurrency));
when(exchangeRate.getBaseCurrency()).thenReturn(Monetary.getCurrency(polCurrency));
when(exchangeRate.getFactor()).thenReturn(new DefaultNumberValue(exchangeEurToUsdRate));
CompletableFuture<Void> future = orderRolloverService.rollover(ledgerFiscalYearRollover, requestContext);
future.join();
assertFalse(future.isCompletedExceptionally());
assertThat(fundDistributionOneTime.getEncumbrance(), equalTo(currEncumbrId1));
assertThat(costOneTime.getPoLineEstimatedPrice(), equalTo(580d));
assertThat(costOneTime.getFyroAdjustmentAmount(), equalTo(-15d));
}
use of org.folio.rest.acq.model.finance.Fund in project mod-orders by folio-org.
the class FundService method getAllFundsByIds.
private CompletableFuture<List<Fund>> getAllFundsByIds(Collection<String> ids, RequestContext requestContext) {
String query = convertIdsToCqlQuery(ids);
RequestEntry requestEntry = new RequestEntry(ENDPOINT).withQuery(query).withLimit(MAX_IDS_FOR_GET_RQ).withOffset(0);
return restClient.get(requestEntry, requestContext, FundCollection.class).thenApply(FundCollection::getFunds).thenApply(funds -> {
if (funds.size() == ids.size()) {
return funds;
}
List<Parameter> parameters = ids.stream().filter(id -> funds.stream().noneMatch(fund -> fund.getId().equals(id))).map(id -> new Parameter().withValue(id).withKey("funds")).collect(Collectors.toList());
throw new HttpException(404, FUNDS_NOT_FOUND.toError().withParameters(parameters));
});
}
Aggregations