use of org.folio.rest.acq.model.finance.Transaction in project mod-orders by folio-org.
the class EncumbranceRelationsHoldersBuilderTest method initMocks.
@BeforeEach
public void initMocks() {
MockitoAnnotations.openMocks(this);
order = new CompositePurchaseOrder().withId(UUID.randomUUID().toString()).withReEncumber(true).withOrderType(CompositePurchaseOrder.OrderType.ONGOING).withOngoing(new Ongoing().withIsSubscription(false));
distribution1 = new FundDistribution().withFundId(UUID.randomUUID().toString()).withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(100d).withEncumbrance(UUID.randomUUID().toString());
line1 = new CompositePoLine().withId(UUID.randomUUID().toString()).withCost(new Cost().withCurrency("USD").withListUnitPrice(68d).withQuantityPhysical(1)).withPurchaseOrderId(order.getId()).withFundDistribution(Collections.singletonList(distribution1));
distribution2 = new FundDistribution().withFundId(UUID.randomUUID().toString()).withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withValue(100d).withEncumbrance(UUID.randomUUID().toString());
line2 = new CompositePoLine().withId(UUID.randomUUID().toString()).withCost(new Cost().withCurrency("USD").withListUnitPrice(34.95).withQuantityPhysical(1)).withPurchaseOrderId(order.getId()).withFundDistribution(Collections.singletonList(distribution2));
distribution3 = new FundDistribution().withFundId(UUID.randomUUID().toString()).withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withExpenseClassId(UUID.randomUUID().toString()).withValue(100d).withEncumbrance(UUID.randomUUID().toString());
line3 = new CompositePoLine().withId(UUID.randomUUID().toString()).withCost(new Cost().withCurrency("EUR").withListUnitPrice(24.99).withQuantityPhysical(1)).withPurchaseOrderId(order.getId()).withFundDistribution(Collections.singletonList(distribution3));
order.setCompositePoLines(List.of(line1, line2, line3));
newEncumbrance1 = new Transaction().withFromFundId(distribution1.getFundId()).withSource(PO_LINE).withEncumbrance(new Encumbrance().withOrderType(ONGOING).withReEncumber(true).withOrderStatus(OPEN).withStatus(UNRELEASED).withSubscription(false).withSourcePurchaseOrderId(order.getId()).withSourcePoLineId(line1.getId()));
newEncumbrance2 = new Transaction().withFromFundId(distribution2.getFundId()).withSource(PO_LINE).withEncumbrance(new Encumbrance().withOrderType(ONGOING).withReEncumber(true).withOrderStatus(OPEN).withStatus(UNRELEASED).withSubscription(false).withSourcePurchaseOrderId(order.getId()).withSourcePoLineId(line2.getId()));
newEncumbrance3 = new Transaction().withFromFundId(distribution3.getFundId()).withSource(PO_LINE).withExpenseClassId(distribution3.getExpenseClassId()).withEncumbrance(new Encumbrance().withOrderType(ONGOING).withReEncumber(true).withOrderStatus(OPEN).withStatus(UNRELEASED).withSubscription(false).withSourcePurchaseOrderId(order.getId()).withSourcePoLineId(line3.getId()));
holder1 = new EncumbranceRelationsHolder().withPurchaseOrder(order).withPoLine(line1).withFundDistribution(distribution1).withNewEncumbrance(newEncumbrance1);
holder2 = new EncumbranceRelationsHolder().withPurchaseOrder(order).withPoLine(line2).withFundDistribution(distribution2).withNewEncumbrance(newEncumbrance2);
holder3 = new EncumbranceRelationsHolder().withPurchaseOrder(order).withPoLine(line3).withFundDistribution(distribution3).withNewEncumbrance(newEncumbrance3);
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-orders by folio-org.
the class EncumbranceServiceTest method testShouldUpdateEncumbranceWithNewAmountFromLineAndFundFromLine.
@Test
void testShouldUpdateEncumbranceWithNewAmountFromLineAndFundFromLine() {
// Given
CompositePurchaseOrder order = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
CompositePoLine line = order.getCompositePoLines().get(0);
FundDistribution fundDistribution = order.getCompositePoLines().get(0).getFundDistribution().get(0);
Transaction encumbrance = getMockAsJson(ENCUMBRANCE_PATH).getJsonArray("transactions").getJsonObject(0).mapTo(Transaction.class);
// When
encumbranceService.updateEncumbrance(fundDistribution, line, encumbrance);
// Then
assertEquals(BigDecimal.valueOf(line.getCost().getListUnitPrice()), BigDecimal.valueOf(encumbrance.getAmount()));
assertEquals(BigDecimal.valueOf(encumbrance.getAmount()), BigDecimal.valueOf(encumbrance.getEncumbrance().getInitialAmountEncumbered()));
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-orders by folio-org.
the class EncumbranceServiceTest method shouldNotCallRemoveEncumbranceLinks.
@Test
void shouldNotCallRemoveEncumbranceLinks() {
// Given
String poLineId = UUID.randomUUID().toString();
String orderId = UUID.randomUUID().toString();
String encumbrance1Id = UUID.randomUUID().toString();
String encumbrance2Id = UUID.randomUUID().toString();
Transaction encumbrance1 = new Transaction().withId(encumbrance1Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId));
Transaction encumbrance2 = new Transaction().withId(encumbrance2Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId));
List<Transaction> transactions = List.of(encumbrance1, encumbrance2);
when(orderInvoiceRelationService.isOrderLinkedToAnInvoice(eq(orderId), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(false));
// When
CompletableFuture<Void> result = encumbranceService.deleteEncumbranceLinksInInvoiceLines(transactions, requestContextMock);
assertFalse(result.isCompletedExceptionally());
result.join();
// Then
verify(orderInvoiceRelationService, times(1)).isOrderLinkedToAnInvoice(eq(orderId), eq(requestContextMock));
verify(invoiceLineService, never()).getInvoiceLinesByOrderLineIds(any(), any());
verify(invoiceLineService, never()).removeEncumbranceLinks(any(), any(), any());
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-orders by folio-org.
the class EncumbranceServiceTest method test.
@Test
void test() {
// Given
String fundId = "df876cba-eeec-4901-bce7-cc2260b0a536";
FundDistribution fundDistribution = new FundDistribution();
fundDistribution.setFundId(fundId);
FiscalYear fiscalYear = new FiscalYear();
fiscalYear.setId(UUID.randomUUID().toString());
CompositePoLine poLine = new CompositePoLine();
poLine.withFundDistribution(List.of(fundDistribution));
String orderId = UUID.randomUUID().toString();
Transaction encumbrance = new Transaction().withId(UUID.randomUUID().toString()).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId));
Transaction encumbrance2 = new Transaction().withId(UUID.randomUUID().toString()).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId));
List<Transaction> transactions = new ArrayList<>();
transactions.add(encumbrance);
transactions.add(encumbrance2);
TransactionCollection transactionCollection = new TransactionCollection().withTransactions(transactions).withTotalRecords(1);
doReturn(completedFuture(fiscalYear)).when(fiscalYearService).getCurrentFiscalYearByFundId(anyString(), eq(requestContextMock));
doReturn(CompletableFuture.completedFuture(transactionCollection)).when(transactionService).getTransactions(anyString(), anyInt(), anyInt(), eq(requestContextMock));
// When
CompletableFuture<List<Transaction>> result = encumbranceService.getPoLineReleasedEncumbrances(poLine, requestContextMock);
assertFalse(result.isCompletedExceptionally());
result.join();
// Then
verify(transactionService, times(1)).getTransactions(anyString(), anyInt(), anyInt(), eq(requestContextMock));
}
use of org.folio.rest.acq.model.finance.Transaction in project mod-orders by folio-org.
the class TransactionSummariesServiceTest method testShouldTransactionsCreatedForEncumbrances.
@Test
void testShouldTransactionsCreatedForEncumbrances() {
// Given
CompositePurchaseOrder order = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
CompositePoLine line = order.getCompositePoLines().get(0);
Transaction encumbrance = getMockAsJson(ENCUMBRANCE_PATH).getJsonArray("transactions").getJsonObject(0).mapTo(Transaction.class);
FundDistribution fundDistribution = order.getCompositePoLines().get(0).getFundDistribution().get(0);
// When
transactionSummariesService.updateOrderTransactionSummary(order.getId(), 1, requestContext);
// Then
assertNull(transactionSummariesService.getOrderTransactionSummary(order.getId(), requestContext));
}
Aggregations