Search in sources :

Example 1 with Invoice

use of org.folio.rest.acq.model.invoice.Invoice 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 Invoice

use of org.folio.rest.acq.model.invoice.Invoice 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 Invoice

use of org.folio.rest.acq.model.invoice.Invoice 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

Invoice (org.folio.rest.acq.model.invoice.Invoice)3 InvoiceLine (org.folio.rest.acq.model.invoice.InvoiceLine)3 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)3 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)3 Piece (org.folio.rest.jaxrs.model.Piece)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CsvSource (org.junit.jupiter.params.provider.CsvSource)3