Search in sources :

Example 16 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PieceDeleteFlowPoLineServiceTest method elecDeleteLocationStrategyShouldDecreaseQuantityForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame.

@Test
@DisplayName("Should delete POL location if 1 electronic piece with location to electronic pol with 1 location and same location id as in piece")
void elecDeleteLocationStrategyShouldDecreaseQuantityForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame() throws ExecutionException, InterruptedException {
    String orderId = UUID.randomUUID().toString();
    String locationId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    Piece piece = new Piece().withPoLineId(lineId).withLocationId(locationId).withFormat(Piece.Format.ELECTRONIC);
    Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
    List<Location> locations = new ArrayList<>();
    locations.add(loc);
    Cost cost = new Cost().withQuantityElectronic(1).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING);
    PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.ELECTRONIC_RESOURCE).withId(lineId).withEresource(eresource).withLocations(List.of(loc)).withCost(cost);
    PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(true);
    incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
    doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
    // When
    pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
    // Then
    CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
    assertNull(poLineToSave.getCost().getQuantityPhysical());
    assertEquals(0, poLineToSave.getCost().getQuantityElectronic());
    assertEquals(Collections.emptyList(), poLineToSave.getLocations());
    verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) ArrayList(java.util.ArrayList) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 17 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PieceDeleteFlowPoLineServiceTest method shouldDecreasePhysicalQuantityTo1ForCostIfInitiallyWas2AndPOLWithoutLocation.

@ParameterizedTest
@DisplayName("Should decrease quantity for cost if initially POL without location")
@CsvSource(value = { "Physical Resource:None:2:Physical:1", "Physical Resource:Instance:2:Physical:1", "Physical Resource:None:1:Physical:0", "Other:None:2:Other:1", "Other:None:1:Other:0" }, delimiter = ':')
void shouldDecreasePhysicalQuantityTo1ForCostIfInitiallyWas2AndPOLWithoutLocation(String lineType, String createInventory, int qty, String pieceFormat, int expQty) throws ExecutionException, InterruptedException {
    String orderId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    Piece.Format pieceFormatE = Piece.Format.fromValue(pieceFormat);
    Piece piece = new Piece().withPoLineId(lineId).withFormat(pieceFormatE);
    Cost cost = new Cost();
    PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.fromValue(lineType)).withId(lineId).withCost(cost);
    Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.fromValue(createInventory));
    originPoLine.withPhysical(physical);
    cost.withQuantityPhysical(qty).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice((double) qty);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
    PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(true);
    incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
    doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
    // When
    pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
    // Then
    CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
    assertNull(poLineToSave.getCost().getQuantityElectronic());
    assertEquals(expQty, poLineToSave.getCost().getQuantityPhysical());
    assertEquals(0, poLineToSave.getLocations().size());
    verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 18 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PieceDeleteFlowPoLineServiceTest method shouldDecreaseElectronicQuantityTo1ForCostIfInitiallyWas2AndPOLWithoutLocation.

@ParameterizedTest
@DisplayName("Should decrease quantity for cost if initially POL without location")
@CsvSource(value = { "Electronic Resource:Instance:2:Electronic:1", "Electronic Resource:None:2:Electronic:1", "Electronic Resource:None:1:Electronic:0" }, delimiter = ':')
void shouldDecreaseElectronicQuantityTo1ForCostIfInitiallyWas2AndPOLWithoutLocation(String lineType, String createInventory, int qty, String pieceFormat, int expQty) throws ExecutionException, InterruptedException {
    String orderId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    Piece.Format pieceFormatE = Piece.Format.fromValue(pieceFormat);
    Piece piece = new Piece().withPoLineId(lineId).withFormat(pieceFormatE);
    Cost cost = new Cost();
    PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.fromValue(lineType)).withId(lineId).withCost(cost);
    Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.fromValue(createInventory));
    originPoLine.withEresource(eresource);
    cost.withQuantityElectronic(qty).withListUnitPriceElectronic(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice((double) qty);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
    PieceDeletionHolder incomingUpdateHolder = new PieceDeletionHolder().withPieceToDelete(piece).withDeleteHolding(true);
    incomingUpdateHolder.withOrderInformation(purchaseOrder, originPoLine);
    doReturn(completedFuture(null)).when(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    doReturn(completedFuture(null)).when(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
    // When
    pieceDeleteFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
    // Then
    CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
    assertNull(poLineToSave.getCost().getQuantityPhysical());
    assertEquals(expQty, poLineToSave.getCost().getQuantityElectronic());
    assertEquals(0, poLineToSave.getLocations().size());
    verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
    verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) PieceDeletionHolder(org.folio.models.pieces.PieceDeletionHolder) PoLine(org.folio.rest.jaxrs.model.PoLine) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost) Eresource(org.folio.rest.jaxrs.model.Eresource) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PieceUpdateFlowInventoryManagerTest method shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding.

@Test
void shouldDeleteHoldingWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding() {
    String orderId = UUID.randomUUID().toString();
    String holdingFromStorageId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    String pieceId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
    JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
    holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
    Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
    Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
    Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1);
    PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
    holder.withOrderInformation(purchaseOrder, poLine);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    doReturn(completedFuture(new JsonObject())).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
    doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
    doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
    doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    doReturn(completedFuture(itemId)).when(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
    pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
    verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
    verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    verify(pieceUpdateInventoryService).manualPieceFlowCreateItemRecord(pieceToUpdate, holder.getPoLineToSave(), requestContext);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) ArrayList(java.util.ArrayList) Title(org.folio.rest.jaxrs.model.Title) JsonObject(io.vertx.core.json.JsonObject) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 20 with PurchaseOrder

use of org.folio.rest.jaxrs.model.PurchaseOrder in project mod-orders by folio-org.

the class PieceUpdateFlowInventoryManagerTest method shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding.

@Test
void shouldUpdateItemWithNewHoldingIdWhenPhysPieceUpdateForPackagePoLineWithCreateInventoryAllAndPieceContainsNewHolding() {
    String orderId = UUID.randomUUID().toString();
    String holdingFromStorageId = UUID.randomUUID().toString();
    String holdingId = UUID.randomUUID().toString();
    String lineId = UUID.randomUUID().toString();
    String titleId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    String pieceId = UUID.randomUUID().toString();
    String instanceId = UUID.randomUUID().toString();
    Title title = new Title().withId(titleId).withPoLineId(lineId).withInstanceId(instanceId);
    JsonObject item = new JsonObject().put(ID, itemId);
    item.put(ITEM_STATUS, new JsonObject().put(ITEM_STATUS_NAME, ItemStatus.ON_ORDER.value()));
    item.put(ITEM_HOLDINGS_RECORD_ID, holdingFromStorageId);
    JsonObject holding = new JsonObject().put(ID, holdingFromStorageId);
    holding.put(HOLDING_PERMANENT_LOCATION_ID, UUID.randomUUID().toString());
    Piece pieceFromStorage = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingFromStorageId).withFormat(Piece.Format.PHYSICAL);
    Piece pieceToUpdate = new Piece().withId(pieceId).withTitleId(titleId).withItemId(itemId).withPoLineId(lineId).withHoldingId(holdingId).withFormat(Piece.Format.PHYSICAL);
    Location loc = new Location().withHoldingId(holdingId).withQuantityElectronic(1).withQuantity(1);
    Cost cost = new Cost().withQuantityElectronic(1);
    PoLine poLine = new PoLine().withIsPackage(true).withPurchaseOrderId(orderId).withId(lineId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM)).withLocations(List.of(loc)).withCost(cost);
    PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(PurchaseOrder.WorkflowStatus.OPEN);
    PieceUpdateHolder holder = new PieceUpdateHolder().withPieceToUpdate(pieceToUpdate).withPieceFromStorage(pieceFromStorage).withCreateItem(true).withDeleteHolding(true);
    holder.withOrderInformation(purchaseOrder, poLine);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    doReturn(completedFuture(item)).when(inventoryManager).getItemRecordById(pieceToUpdate.getItemId(), true, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItem(item, requestContext);
    doReturn(completedFuture(List.of(itemId))).when(inventoryManager).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    doReturn(completedFuture(null)).when(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    doReturn(completedFuture(holding)).when(inventoryManager).getHoldingById(holder.getPieceFromStorage().getHoldingId(), true, requestContext);
    doReturn(completedFuture(new ArrayList())).when(inventoryManager).getItemsByHoldingId(holder.getPieceFromStorage().getHoldingId(), requestContext);
    doReturn(completedFuture(null)).when(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    pieceUpdateFlowInventoryManager.processInventory(holder, requestContext).join();
    assertEquals(holdingId, item.getString(ITEM_HOLDINGS_RECORD_ID));
    assertEquals(holder.getPoLineToSave().getId(), item.getString(ITEM_PURCHASE_ORDER_LINE_IDENTIFIER));
    verify(titlesService).getTitleById(pieceToUpdate.getTitleId(), requestContext);
    verify(inventoryManager, times(0)).getOrCreateHoldingsRecord(eq(holder.getInstanceId()), any(Location.class), eq(requestContext));
    verify(pieceUpdateInventoryService).deleteHoldingConnectedToPiece(holder.getPieceFromStorage(), requestContext);
    verify(inventoryManager).updateItemWithPieceFields(holder.getPieceToUpdate(), requestContext);
    verify(inventoryManager, times(0)).createMissingElectronicItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    verify(inventoryManager, times(0)).createMissingPhysicalItems(holder.getPoLineToSave(), pieceToUpdate, 1, requestContext);
    verify(inventoryManager).updateItem(item, requestContext);
}
Also used : Physical(org.folio.rest.jaxrs.model.Physical) PieceUpdateHolder(org.folio.models.pieces.PieceUpdateHolder) Piece(org.folio.rest.jaxrs.model.Piece) PoLine(org.folio.rest.jaxrs.model.PoLine) ArrayList(java.util.ArrayList) Title(org.folio.rest.jaxrs.model.Title) JsonObject(io.vertx.core.json.JsonObject) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Aggregations

PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)59 Test (org.junit.jupiter.api.Test)52 PoLine (org.folio.rest.jaxrs.model.PoLine)49 Cost (org.folio.rest.jaxrs.model.Cost)46 Piece (org.folio.rest.jaxrs.model.Piece)42 Location (org.folio.rest.jaxrs.model.Location)39 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)32 Eresource (org.folio.rest.jaxrs.model.Eresource)28 Physical (org.folio.rest.jaxrs.model.Physical)24 JsonObject (io.vertx.core.json.JsonObject)23 ArrayList (java.util.ArrayList)23 DisplayName (org.junit.jupiter.api.DisplayName)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 PieceCreationHolder (org.folio.models.pieces.PieceCreationHolder)12 PieceDeletionHolder (org.folio.models.pieces.PieceDeletionHolder)12 PieceUpdateHolder (org.folio.models.pieces.PieceUpdateHolder)12 List (java.util.List)10 Map (java.util.Map)10 CompletableFuture (java.util.concurrent.CompletableFuture)10 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)10