use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalAndNoLocationInTheLineButUpdateCostQty.
@Test
@DisplayName("Add 1 physical piece without location id to physical pol without location and physical qty and create inventory NONE")
void shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalAndNoLocationInTheLineButUpdateCostQty() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withFormat(Piece.Format.PHYSICAL);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.NONE);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withEresource(eresource).withPhysical(physical).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).withCreateItem(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
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertEquals(0, poLineToSave.getLocations().size());
assertEquals(2, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldNotUpdateLocationIfCreateInventoryNoneForElectronicButUpdateCostQty.
@Test
@DisplayName("Add 1 electronic piece without location id to mixed pol with 1 location with location id and physical qty and create inventory NONE")
void shouldNotUpdateLocationIfCreateInventoryNoneForElectronicButUpdateCostQty() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withFormat(Piece.Format.ELECTRONIC);
Location loc = new Location().withLocationId(locationId).withQuantityPhysical(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.NONE);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).withCreateItem(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
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertEquals(1, poLineToSave.getLocations().size());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertNull(poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceCreateFlowPoLineServiceTest method shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalButUpdateCostQty.
@Test
@DisplayName("Add 1 physical piece without location id to mixed pol with 1 location with location id and physical qty and create inventory NONE")
void shouldNotUpdateLocationIfCreateInventoryNoneForPhysicalButUpdateCostQty() throws ExecutionException, InterruptedException {
String orderId = UUID.randomUUID().toString();
String locationId = UUID.randomUUID().toString();
String lineId = UUID.randomUUID().toString();
Piece pieceToCreate = new Piece().withPoLineId(lineId).withFormat(Piece.Format.PHYSICAL);
Location loc = new Location().withLocationId(locationId).withQuantityElectronic(1).withQuantity(1);
Cost cost = new Cost().withQuantityElectronic(1).withQuantityPhysical(1).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(1d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Eresource eresource = new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.NONE);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.P_E_MIX).withId(lineId).withEresource(eresource).withPhysical(physical).withLocations(List.of(loc)).withCost(cost);
PieceCreationHolder incomingUpdateHolder = new PieceCreationHolder().withPieceToCreate(pieceToCreate).withCreateItem(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
pieceCreateFlowPoLineService.updatePoLine(incomingUpdateHolder, requestContext).get();
// Then
CompositePoLine poLineToSave = incomingUpdateHolder.getPoLineToSave();
assertEquals(1, poLineToSave.getLocations().size());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityElectronic());
assertNull(poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(2, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getCost().getQuantityElectronic());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.Physical in project mod-orders by folio-org.
the class PieceDeleteFlowPoLineServiceTest method physDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame.
@Test
@DisplayName("Delete 1 physical piece with location to physical pol with 1 location and same location id as in piece")
void physDeleteStrategyShouldDecreaseQuantityTo1ForCostAndLocationIfInitiallyWas1AndLocationIdInPOLAndPieceTheSame() 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.PHYSICAL);
Location loc = new Location().withLocationId(locationId).withQuantityPhysical(2).withQuantity(2);
List<Location> locations = new ArrayList<>();
locations.add(loc);
Cost cost = new Cost().withQuantityPhysical(2).withListUnitPrice(1d).withExchangeRate(1d).withCurrency("USD").withPoLineEstimatedPrice(2d);
PurchaseOrder purchaseOrder = new PurchaseOrder().withId(orderId).withWorkflowStatus(OPEN);
Physical physical = new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING_ITEM);
PoLine originPoLine = new PoLine().withIsPackage(false).withPurchaseOrderId(orderId).withOrderFormat(PoLine.OrderFormat.PHYSICAL_RESOURCE).withId(lineId).withPhysical(physical).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().getQuantityElectronic());
assertEquals(1, poLineToSave.getCost().getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().size());
assertNull(poLineToSave.getLocations().get(0).getQuantityElectronic());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantityPhysical());
assertEquals(1, poLineToSave.getLocations().get(0).getQuantity());
verify(receivingEncumbranceStrategy).processEncumbrances(incomingUpdateHolder.getPurchaseOrderToSave(), incomingUpdateHolder.getPurchaseOrderToSave(), requestContext);
verify(purchaseOrderLineService).saveOrderLine(incomingUpdateHolder.getPoLineToSave(), requestContext);
}
use of org.folio.rest.jaxrs.model.Physical 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);
}
Aggregations