Search in sources :

Example 6 with InvoiceLine

use of org.folio.rest.acq.model.invoice.InvoiceLine in project mod-orders by folio-org.

the class EncumbranceServiceTest method shouldCallRemoveEncumbranceLinks.

@Test
void shouldCallRemoveEncumbranceLinks() {
    // Given
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String orderId = UUID.randomUUID().toString();
    String encumbrance1Id = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String encumbrance3Id = UUID.randomUUID().toString();
    Transaction encumbrance1 = new Transaction().withId(encumbrance1Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId1));
    Transaction encumbrance2 = new Transaction().withId(encumbrance2Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId1));
    Transaction encumbrance3 = new Transaction().withId(encumbrance3Id).withEncumbrance(new Encumbrance().withSourcePurchaseOrderId(orderId).withSourcePoLineId(poLineId2));
    List<Transaction> transactions = List.of(encumbrance1, encumbrance2, encumbrance3);
    List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id))).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)))));
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId2).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance3Id)))));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
    when(orderInvoiceRelationService.isOrderLinkedToAnInvoice(eq(orderId), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(true));
    when(invoiceLineService.getInvoiceLinesByOrderLineIds(anyList(), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(invoiceLines));
    when(invoiceLineService.removeEncumbranceLinks(anyList(), anyList(), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
    // When
    CompletableFuture<Void> result = encumbranceService.deleteEncumbranceLinksInInvoiceLines(transactions, requestContextMock);
    assertFalse(result.isCompletedExceptionally());
    result.join();
    // Then
    verify(invoiceLineService, times(1)).removeEncumbranceLinks(argThat(lines -> lines.size() == 2), argThat(ids -> ids.containsAll(transactionIds)), eq(requestContextMock));
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Header(io.restassured.http.Header) X_OKAPI_USER_ID(org.folio.TestConstants.X_OKAPI_USER_ID) PoLine(org.folio.rest.jaxrs.model.PoLine) Context(io.vertx.core.Context) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) MockitoAnnotations(org.mockito.MockitoAnnotations) BigDecimal(java.math.BigDecimal) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) Mockito.doReturn(org.mockito.Mockito.doReturn) BASE_MOCK_DATA_PATH(org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH) UUID(java.util.UUID) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) TestConfig.mockPort(org.folio.TestConfig.mockPort) Test(org.junit.jupiter.api.Test) List(java.util.List) X_OKAPI_TOKEN(org.folio.TestConstants.X_OKAPI_TOKEN) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Mockito.inOrder(org.mockito.Mockito.inOrder) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InvoiceLineService(org.folio.service.invoice.InvoiceLineService) Mock(org.mockito.Mock) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) Transaction(org.folio.rest.acq.model.finance.Transaction) ArrayList(java.util.ArrayList) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) InjectMocks(org.mockito.InjectMocks) InOrder(org.mockito.InOrder) Vertx(io.vertx.core.Vertx) Mockito.times(org.mockito.Mockito.times) FiscalYearService(org.folio.service.finance.FiscalYearService) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) ENCUMBRANCE_PATH(org.folio.rest.impl.MockServer.ENCUMBRANCE_PATH) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Transaction(org.folio.rest.acq.model.finance.Transaction) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) Test(org.junit.jupiter.api.Test)

Example 7 with InvoiceLine

use of org.folio.rest.acq.model.invoice.InvoiceLine in project mod-orders by folio-org.

the class ReOpenCompositeOrderManagerTest method shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveDifferentStatuses.

@ParameterizedTest
@CsvSource(value = { "Open:Approved:Expected:Received:Awaiting Receipt:Partially Received:Awaiting Payment:Partially Paid", "Approved:Open:Received:Expected:Partially Received:Awaiting Receipt:Partially Paid:Awaiting Payment", "Paid:Open:Expected:Received:Awaiting Receipt:Partially Received:Partially Paid:Awaiting Payment" }, delimiter = ':')
void shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveDifferentStatuses(String invoiceStatus1, String invoiceStatus2, String pieceStatus1, String pieceStatus2, String expReceiptStatus1, String expReceiptStatus2, String expPaymentStatus1, String expPaymentStatus2) throws ExecutionException, InterruptedException {
    CompositePurchaseOrder oldOrder = getMockAsJson(ORDER_PATH).mapTo(CompositePurchaseOrder.class);
    CompositePoLine poLine1 = oldOrder.getCompositePoLines().get(0);
    String poLineId1 = poLine1.getId();
    String encumbrance1Id = poLine1.getFundDistribution().get(0).getEncumbrance();
    CompositePoLine poLine2 = JsonObject.mapFrom(poLine1).mapTo(CompositePoLine.class);
    String poLineId2 = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String oldInstance2 = UUID.randomUUID().toString();
    poLine2.setId(poLineId2);
    poLine2.getFundDistribution().get(0).setEncumbrance(encumbrance2Id);
    poLine2.setInstanceId(oldInstance2);
    oldOrder.setCompositePoLines(List.of(poLine1, poLine2));
    CompositePurchaseOrder newOrder = JsonObject.mapFrom(oldOrder).mapTo(CompositePurchaseOrder.class);
    newOrder.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
    String invoiceId1 = UUID.randomUUID().toString();
    Invoice invoice1 = new Invoice().withId(invoiceId1).withStatus(Invoice.Status.fromValue(invoiceStatus1));
    String invoiceId2 = UUID.randomUUID().toString();
    Invoice invoice2 = new Invoice().withId(invoiceId2).withStatus(Invoice.Status.fromValue(invoiceStatus2));
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice1.getId()).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id)));
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice2.getId()).withPoLineId(poLineId2).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
    List<Invoice> invoices = List.of(invoice1, invoice2);
    Piece piece1 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus1)).withPoLineId(poLineId1).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
    Piece piece2 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus2)).withPoLineId(poLineId2).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
    doReturn(closedToOpenEncumbranceStrategy).when(encumbranceWorkflowStrategyFactory).getStrategy(eq(OrderWorkflowType.CLOSED_TO_OPEN));
    doReturn(completedFuture(null)).when(closedToOpenEncumbranceStrategy).processEncumbrances(eq(newOrder), eq(oldOrder), eq(requestContext));
    doReturn(completedFuture(invoiceLines)).when(invoiceLineService).getInvoiceLinesByOrderLineIds(List.of(poLineId1, poLineId2), requestContext);
    doReturn(completedFuture(invoices)).when(invoiceService).getInvoicesByOrderId(oldOrder.getId(), requestContext);
    doReturn(completedFuture(List.of(piece1, piece2))).when(pieceStorageService).getPiecesByLineIdsByChunks(List.of(poLineId1, poLineId2), requestContext);
    reOpenCompositeOrderManager.process(newOrder, oldOrder, requestContext).get();
    assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus1), newOrder.getCompositePoLines().get(0).getReceiptStatus());
    assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus1), newOrder.getCompositePoLines().get(0).getPaymentStatus());
    assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus2), newOrder.getCompositePoLines().get(1).getReceiptStatus());
    assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus2), newOrder.getCompositePoLines().get(1).getPaymentStatus());
}
Also used : Invoice(org.folio.rest.acq.model.invoice.Invoice) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InvoiceLine (org.folio.rest.acq.model.invoice.InvoiceLine)7 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)4 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)4 Invoice (org.folio.rest.acq.model.invoice.Invoice)3 InvoiceLineCollection (org.folio.rest.acq.model.invoice.InvoiceLineCollection)3 Piece (org.folio.rest.jaxrs.model.Piece)3 Test (org.junit.jupiter.api.Test)3 Vertx (io.vertx.core.Vertx)2 JsonObject (io.vertx.core.json.JsonObject)2 List (java.util.List)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Adjustment (org.folio.rest.acq.model.invoice.Adjustment)2 RequestContext (org.folio.rest.core.models.RequestContext)2 PoLine (org.folio.rest.jaxrs.model.PoLine)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 Header (io.restassured.http.Header)1