Search in sources :

Example 26 with Transaction

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);
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) EncumbranceRelationsHolder(org.folio.models.EncumbranceRelationsHolder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Ongoing(org.folio.rest.jaxrs.model.Ongoing) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with Transaction

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()));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Example 28 with Transaction

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());
}
Also used : Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 29 with Transaction

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));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) ArrayList(java.util.ArrayList) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 30 with Transaction

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));
}
Also used : FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (org.folio.rest.acq.model.finance.Transaction)79 Test (org.junit.jupiter.api.Test)60 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)31 ArrayList (java.util.ArrayList)29 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)29 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)25 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)24 List (java.util.List)21 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 EncumbranceRelationsHolder (org.folio.models.EncumbranceRelationsHolder)16 RequestContext (org.folio.rest.core.models.RequestContext)16 Budget (org.folio.rest.acq.model.finance.Budget)15 Fund (org.folio.rest.acq.model.finance.Fund)15 RequestEntry (org.folio.rest.core.models.RequestEntry)15 MonetaryAmount (javax.money.MonetaryAmount)14 Cost (org.folio.rest.jaxrs.model.Cost)14 JsonObject (io.vertx.core.json.JsonObject)12 Collectors.toList (java.util.stream.Collectors.toList)12 Error (org.folio.rest.jaxrs.model.Error)11