use of org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection in project mod-orders by folio-org.
the class OrderReEncumberServiceTest method reEncumberWithEmptyHoldersShouldCompleteSuccessfully.
@Test
void reEncumberWithEmptyHoldersShouldCompleteSuccessfully() {
String orderId = UUID.randomUUID().toString();
when(purchaseOrderStorageService.getCompositeOrderById(eq(orderId), eq(requestContext))).thenReturn(completedFuture(new CompositePurchaseOrder().withId(orderId)));
when(spyReEncumbranceHoldersBuilder.buildReEncumbranceHoldersWithOrdersData(any())).thenReturn(Collections.emptyList());
when(spyReEncumbranceHoldersBuilder.withFundsData(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withLedgersData(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withCurrentFiscalYearData(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withRollovers(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withEncumbranceRollover(any())).thenReturn(Collections.emptyList());
when(spyReEncumbranceHoldersBuilder.withBudgets(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withConversions(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withPreviousFyEncumbrances(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
when(spyReEncumbranceHoldersBuilder.withToEncumbrances(any(), any())).thenReturn(completedFuture(Collections.emptyList()));
doNothing().when(budgetRestrictionService).checkEncumbranceRestrictions(anyList());
when(rolloverErrorService.getLedgerFyRolloverErrors(anyString(), any())).thenReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection()));
when(rolloverErrorService.deleteRolloverErrors(anyList(), any())).thenReturn(completedFuture(null));
when(purchaseOrderLineService.saveOrderLines(anyList(), any())).thenReturn(completedFuture(null));
ConversionQuery conversionQuery = ConversionQueryBuilder.of().setBaseCurrency("USD").setTermCurrency("USD").build();
when(exchangeRateProviderResolver.resolve(conversionQuery, requestContext)).thenReturn(exchangeRateProvider);
CompletableFuture<Void> future = orderReEncumberService.reEncumber(orderId, requestContext);
future.join();
assertFalse(future.isCompletedExceptionally());
}
use of org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection 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.LedgerFiscalYearRolloverErrorCollection in project mod-orders by folio-org.
the class OrderReEncumberServiceTest method shouldFilterReEncumberHoldersWithEmptyEncumbranceRollover.
@Test
void shouldFilterReEncumberHoldersWithEmptyEncumbranceRollover() {
CompositePoLine line = new CompositePoLine().withCost(new Cost().withCurrency("USD").withListUnitPrice(1d));
String orderId = UUID.randomUUID().toString();
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPoLine(line).withLedgerId(UUID.randomUUID().toString());
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPoLine(line).withLedgerId(UUID.randomUUID().toString());
List<ReEncumbranceHolder> holders = List.of(holder1, holder2);
when(purchaseOrderStorageService.getCompositeOrderById(eq(orderId), eq(requestContext))).thenReturn(completedFuture(new CompositePurchaseOrder().withId(orderId)));
when(spyReEncumbranceHoldersBuilder.buildReEncumbranceHoldersWithOrdersData(any())).thenReturn(holders);
when(spyReEncumbranceHoldersBuilder.withFundsData(any(), any())).thenReturn(completedFuture(holders));
when(spyReEncumbranceHoldersBuilder.withLedgersData(any(), any())).thenReturn(completedFuture(holders));
when(spyReEncumbranceHoldersBuilder.withCurrentFiscalYearData(any(), any())).thenReturn(completedFuture(holders));
when(spyReEncumbranceHoldersBuilder.withRollovers(any(), any())).thenReturn(completedFuture(holders));
when(spyReEncumbranceHoldersBuilder.withEncumbranceRollover(any())).thenReturn(holders);
when(spyReEncumbranceHoldersBuilder.withBudgets(any(), any())).thenReturn(completedFuture(holders));
when(spyReEncumbranceHoldersBuilder.withConversions(any(), any())).thenReturn(completedFuture(holders));
when(spyReEncumbranceHoldersBuilder.withPreviousFyEncumbrances(any(), any())).thenAnswer(invocation -> completedFuture(invocation.getArgument(0)));
when(spyReEncumbranceHoldersBuilder.withToEncumbrances(any(), any())).thenAnswer(invocation -> completedFuture(invocation.getArgument(0)));
doNothing().when(budgetRestrictionService).checkEncumbranceRestrictions(anyList());
when(rolloverErrorService.getLedgerFyRolloverErrors(anyString(), any())).thenReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection()));
when(rolloverErrorService.deleteRolloverErrors(anyList(), any())).thenReturn(completedFuture(null));
when(purchaseOrderLineService.saveOrderLines(anyList(), any())).thenReturn(completedFuture(null));
CompletableFuture<Void> future = orderReEncumberService.reEncumber(orderId, requestContext);
TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.EMPTY_LIST).withTotalRecords(0);
when(transactionService.getTransactions(anyString(), eq(0), eq(Integer.MAX_VALUE), eq(requestContext))).thenReturn(completedFuture(toTransactionCollection));
when(transactionSummaryService.updateOrderTransactionSummary(eq(orderId), anyInt(), eq(requestContext))).thenReturn(completedFuture(null));
when(transactionService.createTransaction(any(), eq(requestContext))).thenReturn(completedFuture(new Transaction()));
future.join();
assertFalse(future.isCompletedExceptionally());
ArgumentCaptor<List<ReEncumbranceHolder>> argumentCaptor = ArgumentCaptor.forClass(List.class);
verify(spyReEncumbranceHoldersBuilder).withPreviousFyEncumbrances(argumentCaptor.capture(), any());
List<ReEncumbranceHolder> argumentHolders = argumentCaptor.getValue();
assertThat(argumentHolders, hasSize(0));
}
use of org.folio.rest.acq.model.finance.LedgerFiscalYearRolloverErrorCollection in project mod-orders by folio-org.
the class OrderReEncumberServiceTest method shouldVerifyFYROAdjustmentAndFundDistributionValuesWhenMixedFunds.
@Test
void shouldVerifyFYROAdjustmentAndFundDistributionValuesWhenMixedFunds() {
String ledgerId = UUID.randomUUID().toString();
String fromFyId = UUID.randomUUID().toString();
String toFyId = UUID.randomUUID().toString();
String orderId = UUID.randomUUID().toString();
String fund1Id = UUID.randomUUID().toString();
String fund2Id = UUID.randomUUID().toString();
String rolloverId = UUID.randomUUID().toString();
Ledger notRestrictedLedger = new Ledger().withId(ledgerId).withRestrictEncumbrance(false);
double exchangeRate = 1.1d;
Fund fund1 = new Fund().withId(fund1Id).withLedgerId(ledgerId);
Fund fund2 = new Fund().withId(fund2Id).withLedgerId(ledgerId);
Budget notRestrictedBudget1 = new Budget().withId(UUID.randomUUID().toString()).withFundId(fund1Id);
EncumbranceRollover encumbranceRollover = new EncumbranceRollover().withBasedOn(EncumbranceRollover.BasedOn.EXPENDED).withOrderType(EncumbranceRollover.OrderType.ONE_TIME).withIncreaseBy(10d);
LedgerFiscalYearRollover rollover = new LedgerFiscalYearRollover().withId(rolloverId).withLedgerId(ledgerId).withFromFiscalYearId(fromFyId).withToFiscalYearId(toFyId).withEncumbrancesRollover(Collections.singletonList(encumbranceRollover));
CompositePurchaseOrder compPO = new CompositePurchaseOrder().withId(orderId).withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME);
Cost cost1 = new Cost().withListUnitPrice(120d).withQuantityPhysical(1).withExchangeRate(exchangeRate).withCurrency("EUR").withPoLineEstimatedPrice(120d);
Transaction fromEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(40d)).withAmount(20d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
Transaction fromEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(30d)).withAmount(30d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
Transaction toEncumbrance1 = new Transaction().withEncumbrance(new Encumbrance().withStatus(Encumbrance.Status.UNRELEASED).withAmountAwaitingPayment(0d).withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(0d)).withAmount(40d).withFiscalYearId(fromFyId).withFromFundId(fund1Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
Transaction toEncumbrance2 = new Transaction().withEncumbrance(new Encumbrance().withStatus(Encumbrance.Status.UNRELEASED).withAmountAwaitingPayment(0d).withSourcePurchaseOrderId(orderId).withInitialAmountEncumbered(60d).withAmountExpended(0d)).withAmount(30d).withFiscalYearId(fromFyId).withFromFundId(fund2Id).withId(UUID.randomUUID().toString()).withCurrency("USD");
TransactionCollection toTransactionCollection = new TransactionCollection().withTransactions(Collections.EMPTY_LIST).withTotalRecords(0);
FundDistribution fundDistribution1 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(50d).withEncumbrance(fromEncumbrance1.getId()).withFundId(fund1Id);
FundDistribution fundDistribution2 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.AMOUNT).withValue(60d).withEncumbrance(fromEncumbrance2.getId()).withFundId(fund2Id);
CompositePoLine line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withCost(cost1).withFundDistribution(List.of(fundDistribution1, fundDistribution2));
ConversionQuery conversionPoLineToFyQuery = ConversionQueryBuilder.of().setBaseCurrency("EUR").setTermCurrency("USD").set(ExchangeRateProviderResolver.RATE_KEY, exchangeRate).build();
ConversionQuery conversionFyToPoLineQuery = ConversionQueryBuilder.of().setBaseCurrency("USD").setTermCurrency("EUR").set(ExchangeRateProviderResolver.RATE_KEY, exchangeRate).build();
ReEncumbranceHolder holder1 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution1).withLedgerId(ledgerId).withRestrictEncumbrances(notRestrictedLedger.getRestrictEncumbrance()).withBudget(notRestrictedBudget1).withEncumbranceRollover(encumbranceRollover).withPreviousFyEncumbrance(fromEncumbrance1).withNewEncumbrance(toEncumbrance1).withPoLineToFyConversion(exchangeRateProvider.getCurrencyConversion(conversionPoLineToFyQuery)).withFyToPoLineConversion(exchangeRateProvider.getCurrencyConversion(conversionFyToPoLineQuery));
ReEncumbranceHolder holder2 = new ReEncumbranceHolder().withPurchaseOrder(compPO).withRollover(rollover).withPoLine(line1).withFundDistribution(fundDistribution2).withLedgerId(ledgerId).withRestrictEncumbrances(notRestrictedLedger.getRestrictEncumbrance()).withBudget(notRestrictedBudget1).withEncumbranceRollover(encumbranceRollover).withNewEncumbrance(toEncumbrance2).withPreviousFyEncumbrance(fromEncumbrance2).withPoLineToFyConversion(exchangeRateProvider.getCurrencyConversion(conversionPoLineToFyQuery)).withFyToPoLineConversion(exchangeRateProvider.getCurrencyConversion(conversionFyToPoLineQuery));
List<ReEncumbranceHolder> holders = Arrays.asList(holder1, holder2);
when(purchaseOrderStorageService.getCompositeOrderById(anyString(), eq(requestContext))).thenAnswer(invocation -> completedFuture(new CompositePurchaseOrder().withId(invocation.getArgument(0))));
doReturn(holders).when(spyReEncumbranceHoldersBuilder).buildReEncumbranceHoldersWithOrdersData(any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withFundsData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withLedgersData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withCurrentFiscalYearData(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withRollovers(any(), any());
doReturn(holders).when(spyReEncumbranceHoldersBuilder).withEncumbranceRollover(any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withBudgets(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withConversions(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withPreviousFyEncumbrances(any(), any());
doReturn(completedFuture(holders)).when(spyReEncumbranceHoldersBuilder).withToEncumbrances(any(), any());
doNothing().when(budgetRestrictionService).checkEncumbranceRestrictions(anyList());
when(rolloverErrorService.getLedgerFyRolloverErrors(anyString(), any())).thenReturn(completedFuture(new LedgerFiscalYearRolloverErrorCollection()));
when(rolloverErrorService.deleteRolloverErrors(anyList(), any())).thenReturn(completedFuture(null));
when(purchaseOrderLineService.saveOrderLines(anyList(), any())).thenReturn(completedFuture(null));
when(rolloverRetrieveService.getRolloversProgress(eq(rolloverId), any())).thenReturn(completedFuture(Collections.singletonList(success)));
when(exchangeRateProviderResolver.resolve(conversionPoLineToFyQuery, requestContext)).thenReturn(exchangeRateProvider);
when(exchangeRateProviderResolver.resolve(conversionFyToPoLineQuery, requestContext)).thenReturn(exchangeRateProvider);
when(transactionService.getTransactions(anyString(), eq(0), eq(Integer.MAX_VALUE), eq(requestContext))).thenReturn(completedFuture(toTransactionCollection));
when(transactionSummaryService.updateOrderTransactionSummary(eq(orderId), anyInt(), eq(requestContext))).thenReturn(completedFuture(null));
when(transactionService.createTransaction(any(), eq(requestContext))).thenReturn(completedFuture(new Transaction()));
// When
CompletableFuture<Void> future = orderReEncumberService.reEncumber(UUID.randomUUID().toString(), requestContext);
future.join();
// Then
assertFalse(future.isCompletedExceptionally());
assertEquals(-35.3d, line1.getCost().getFyroAdjustmentAmount());
assertEquals(50d, line1.getFundDistribution().get(0).getValue());
assertEquals(42.35d, line1.getFundDistribution().get(1).getValue());
}
Aggregations