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());
}
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());
}
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));
}
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());
}
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);
}
Aggregations