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