Search in sources :

Example 1 with InvoiceLine

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

the class ReOpenCompositeOrderManagerTest method shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveDifferentStatusesAndPolCoveredMoreThenOneInvoice.

@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 shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveDifferentStatusesAndPolCoveredMoreThenOneInvoice(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));
    String invoiceId3 = UUID.randomUUID().toString();
    Invoice invoice3 = new Invoice().withId(invoiceId3).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)));
    InvoiceLine invoiceLine3 = new InvoiceLine().withId(UUID.randomUUID().toString()).withInvoiceId(invoice3.getId()).withPoLineId(poLineId2).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)));
    List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2, invoiceLine3);
    List<Invoice> invoices = List.of(invoice1, invoice2, invoice3);
    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)

Example 2 with InvoiceLine

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

the class ReOpenCompositeOrderManagerTest method shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveSameStatuses.

@ParameterizedTest
@CsvSource(value = { "Open:Expected:Awaiting Receipt:Awaiting Payment", "Approved:Received:Partially Received:Partially Paid", "Paid:Received:Partially Received:Partially Paid" }, delimiter = ':')
void shouldCheckPaymentAndReceiptStatusesIfInvoicesAndPiecesHaveSameStatuses(String invoiceStatus, String pieceStatus, String expReceiptStatus, String expPaymentStatus) 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(invoiceStatus));
    String invoiceId2 = UUID.randomUUID().toString();
    Invoice invoice2 = new Invoice().withId(invoiceId2).withStatus(Invoice.Status.fromValue(invoiceStatus));
    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(pieceStatus)).withPoLineId(poLineId1).withLocationId(UUID.randomUUID().toString()).withHoldingId(UUID.randomUUID().toString());
    Piece piece2 = new Piece().withFormat(Piece.Format.PHYSICAL).withReceivingStatus(Piece.ReceivingStatus.fromValue(pieceStatus)).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(expReceiptStatus), newOrder.getCompositePoLines().get(0).getReceiptStatus());
    assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus), newOrder.getCompositePoLines().get(0).getPaymentStatus());
    assertEquals(CompositePoLine.ReceiptStatus.fromValue(expReceiptStatus), newOrder.getCompositePoLines().get(1).getReceiptStatus());
    assertEquals(CompositePoLine.PaymentStatus.fromValue(expPaymentStatus), 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)

Example 3 with InvoiceLine

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

the class InvoiceLineServiceTest method shouldRemoveEncumbranceLinks.

@Test
void shouldRemoveEncumbranceLinks() {
    // Given
    String poLineId1 = UUID.randomUUID().toString();
    String poLineId2 = UUID.randomUUID().toString();
    String encumbrance1Id = UUID.randomUUID().toString();
    String encumbrance2Id = UUID.randomUUID().toString();
    String encumbrance3Id = UUID.randomUUID().toString();
    List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
    String invoiceLineId1 = UUID.randomUUID().toString();
    InvoiceLine invoiceLine1 = new InvoiceLine().withId(invoiceLineId1).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)))));
    String invoiceLineId2 = UUID.randomUUID().toString();
    InvoiceLine invoiceLine2 = new InvoiceLine().withId(invoiceLineId2).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);
    InvoiceLine expectedInvoiceLine1 = JsonObject.mapFrom(invoiceLine1).mapTo(InvoiceLine.class);
    expectedInvoiceLine1.getFundDistributions().get(0).setEncumbrance(null);
    expectedInvoiceLine1.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
    InvoiceLine expectedInvoiceLine2 = JsonObject.mapFrom(invoiceLine2).mapTo(InvoiceLine.class);
    expectedInvoiceLine2.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
    when(restClient.put(any(RequestEntry.class), any(InvoiceLine.class), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
    when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
    // When
    CompletableFuture<Void> result = invoiceLineService.removeEncumbranceLinks(invoiceLines, transactionIds, requestContextMock);
    assertFalse(result.isCompletedExceptionally());
    result.join();
    // Then
    verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId1.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine1), eq(requestContextMock));
    verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId2.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine2), eq(requestContextMock));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RestClient(org.folio.rest.core.RestClient) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture(java.util.concurrent.CompletableFuture) MockitoAnnotations(org.mockito.MockitoAnnotations) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) InjectMocks(org.mockito.InjectMocks) Vertx(io.vertx.core.Vertx) RequestEntry(org.folio.rest.core.models.RequestEntry) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) LogManager(org.apache.logging.log4j.LogManager) Adjustment(org.folio.rest.acq.model.invoice.Adjustment) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) RequestEntry(org.folio.rest.core.models.RequestEntry) Test(org.junit.jupiter.api.Test)

Example 4 with InvoiceLine

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

the class OrderInvoiceRelationServiceTest method testShouldThrowExceptionWhenOrderLineLinkedToInvoice.

@Test
void testShouldThrowExceptionWhenOrderLineLinkedToInvoice() {
    // GIVEN
    OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(1);
    doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
    PoLine poLineLinkedToInvoice = new PoLine().withId(poLineIdConnectedToInvoice);
    InvoiceLine invoiceLine1 = new InvoiceLine().withInvoiceId(invoiceId).withPoLineId(poLineIdConnectedToInvoice);
    InvoiceLine invoiceLine2 = new InvoiceLine().withInvoiceId(invoiceId).withPoLineId(UUID.randomUUID().toString());
    List<InvoiceLine> invoiceLines = Arrays.asList(invoiceLine1, invoiceLine2);
    InvoiceLineCollection invoiceLineCollection = new InvoiceLineCollection();
    invoiceLineCollection.setInvoiceLines(invoiceLines);
    // WHEN
    when(invoiceLineService.getInvoiceLinesByOrderLineId(eq(poLineIdConnectedToInvoice), any())).thenReturn(completedFuture(invoiceLines));
    CompletableFuture<Void> future = orderInvoiceRelationService.checkOrderPOLineLinkedToInvoiceLine(poLineLinkedToInvoice, requestContext);
    // THEN
    CompletionException exception = assertThrows(CompletionException.class, future::join);
    HttpException httpException = (HttpException) exception.getCause();
    assertEquals(ErrorCodes.ORDER_RELATES_TO_INVOICE.getDescription(), httpException.getMessage());
}
Also used : OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) PoLine(org.folio.rest.jaxrs.model.PoLine) CompletionException(java.util.concurrent.CompletionException) OrderInvoiceRelationship(org.folio.rest.acq.model.OrderInvoiceRelationship) HttpException(org.folio.rest.core.exceptions.HttpException) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) Test(org.junit.jupiter.api.Test)

Example 5 with InvoiceLine

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

the class MockServer method handleGetInvoiceLines.

private void handleGetInvoiceLines(RoutingContext ctx) {
    // for testReopenOrderUnreleasesEncumbrancesUnlessInvoiceLineHasReleaseEncumbrance
    String query = ctx.request().params().get("query");
    String poLineId1 = "50fb5514-cdf1-11e8-a8d5-f2801f1b9fd1";
    String poLineId2 = "4d3d5eb0-b32a-11eb-8529-0242ac130003";
    InvoiceLineCollection invoiceLineCollection;
    if (query.equals("poLineId == " + poLineId1 + " and releaseEncumbrance == true")) {
        invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(Collections.emptyList()).withTotalRecords(0);
    } else if (query.equals("poLineId == " + poLineId2 + " and releaseEncumbrance == true")) {
        InvoiceLine invoiceLine = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId2).withReleaseEncumbrance(true);
        invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(List.of(invoiceLine)).withTotalRecords(1);
    } else if (query.matches("poLineId(.*)")) {
        InvoiceLine invoiceLine = new InvoiceLine().withId(UUID.randomUUID().toString()).withPoLineId(poLineId2).withInvoiceId(UUID.randomUUID().toString()).withReleaseEncumbrance(true);
        invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(List.of(invoiceLine)).withTotalRecords(1);
    } else {
        serverResponse(ctx, HttpStatus.HTTP_NOT_FOUND.toInt(), APPLICATION_JSON, "invoice line not found");
        return;
    }
    JsonObject jo = JsonObject.mapFrom(invoiceLineCollection);
    serverResponse(ctx, 200, APPLICATION_JSON, jo.encodePrettily());
    addServerRqRsData(HttpMethod.GET, "invoiceLines", jo);
}
Also used : InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) JsonObject(io.vertx.core.json.JsonObject) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection)

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