Skip to content

Commit

Permalink
[MODORDERS-1079] Change in PE mix location updates + async bug fix (#882
Browse files Browse the repository at this point in the history
)
  • Loading branch information
damien-git authored Apr 4, 2024
1 parent d74496e commit b672c3e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
54 changes: 33 additions & 21 deletions src/main/java/org/folio/service/pieces/flows/strategies/ProcessInventoryMixedStrategy.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static java.util.stream.Collectors.toList;
import static org.folio.orders.utils.HelperUtils.collectResultsOnSuccess;
import static org.folio.orders.utils.PoLineCommonUtil.isHoldingUpdateRequiredForEresource;
import static org.folio.orders.utils.PoLineCommonUtil.isHoldingUpdateRequiredForPhysical;
import static org.folio.service.inventory.InventoryManager.HOLDING_PERMANENT_LOCATION_ID;
import static org.folio.service.inventory.InventoryManager.ID;

Expand Down Expand Up @@ -78,31 +80,41 @@ private void updateLocationWithHoldingInfo(JsonObject holding, Location location
private void updateLocations(CompositePoLine compPOL) {
List<Location> locations = new ArrayList<>();
for (Location location : compPOL.getLocations()) {
if (location.getQuantityPhysical() != null && location.getQuantityPhysical() > 0) {
Location physicalLocation = new Location();
if (PoLineCommonUtil.isHoldingUpdateRequiredForPhysical(compPOL)) {
physicalLocation.setHoldingId(location.getHoldingId());
boolean physicalResource = location.getQuantityPhysical() != null && location.getQuantityPhysical() > 0;
boolean electronicResource = location.getQuantityElectronic() != null && location.getQuantityElectronic() > 0;
boolean physicalHolding = physicalResource && isHoldingUpdateRequiredForPhysical(compPOL);
boolean electronicHolding = electronicResource && isHoldingUpdateRequiredForEresource(compPOL);
Location newLocation = JsonObject.mapFrom(location).mapTo(Location.class);
// Physical/electronic locations have to be merged when they have the same holdingId or locationId,
// but separate otherwise, and they can't have both holdingId and locationId.
// This will split locations only if one resource type is getting a holdings update but not the other.
if (electronicHolding && physicalResource && !physicalHolding) {
Location newElectronicLocation = JsonObject.mapFrom(location).mapTo(Location.class);
newElectronicLocation.setQuantityPhysical(null);
newElectronicLocation.setLocationId(null);
newElectronicLocation.setQuantity(location.getQuantityElectronic());
locations.add(newElectronicLocation);
newLocation.setQuantityElectronic(null);
newLocation.setHoldingId(null);
newLocation.setQuantity(location.getQuantityPhysical());
} else if (physicalHolding && electronicResource && !electronicHolding) {
Location newPhysicalLocation = JsonObject.mapFrom(location).mapTo(Location.class);
newPhysicalLocation.setQuantityElectronic(null);
newPhysicalLocation.setLocationId(null);
newPhysicalLocation.setQuantity(location.getQuantityPhysical());
locations.add(newPhysicalLocation);
newLocation.setQuantityPhysical(null);
newLocation.setHoldingId(null);
newLocation.setQuantity(location.getQuantityElectronic());
} else {
if (physicalHolding || electronicHolding) {
newLocation.setLocationId(null);
} else {
physicalLocation.setLocationId(location.getLocationId());
newLocation.setHoldingId(null);
}
physicalLocation.setQuantity(location.getQuantityPhysical());
physicalLocation.setQuantityPhysical(location.getQuantityPhysical());
locations.add(physicalLocation);
}

if (location.getQuantityElectronic() != null && location.getQuantityElectronic() > 0) {
Location electronicLocation = new Location();
if (PoLineCommonUtil.isHoldingUpdateRequiredForEresource(compPOL)) {
electronicLocation.setHoldingId(location.getHoldingId());
} else {
electronicLocation.setLocationId(location.getLocationId());
}
electronicLocation.setQuantity(location.getQuantityElectronic());
electronicLocation.setQuantityElectronic(location.getQuantityElectronic());
locations.add(electronicLocation);
}
locations.add(newLocation);
}
compPOL.setLocations(null);
compPOL.setLocations(locations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected Future<Void> updatePoLine(PieceUpdateHolder holder, RequestContext req
CompositePoLine originPoLine = holder.getOriginPoLine();

return pieceStorageService.getPiecesByLineId(originPoLine.getId(), requestContext)
.map(pieces -> {
.compose(pieces -> {
CompositePurchaseOrder order = holder.getOriginPurchaseOrder();
if (order.getOrderType() != OrderType.ONE_TIME || order.getWorkflowStatus() != WorkflowStatus.OPEN) {
return Future.succeededFuture();
Expand All @@ -116,7 +116,7 @@ protected Future<Void> updatePoLine(PieceUpdateHolder holder, RequestContext req
CompositePoLine poLineToSave = holder.getPoLineToSave();
poLineToSave.setReceiptStatus(calculatePoLineReceiptStatus(originPoLine, pieces, piecesToUpdate));
return purchaseOrderLineService.saveOrderLine(poLineToSave, requestContext);
}).compose(t -> {
}).compose(v -> {
if (!Boolean.TRUE.equals(originPoLine.getIsPackage()) &&
!Boolean.TRUE.equals(originPoLine.getCheckinItems())) {
return updatePoLineService.updatePoLine(holder, requestContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class PieceUpdateFlowManagerTest {
@Autowired PieceService pieceService;
@Autowired BasePieceFlowHolderBuilder basePieceFlowHolderBuilder;
@Autowired PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService;
@Autowired PurchaseOrderLineService purchaseOrderLineService;

private final Context ctx = getFirstContextFromVertx(getVertx());
@Mock
Expand Down Expand Up @@ -119,8 +120,8 @@ public static void after() {
@AfterEach
void resetMocks() {
clearServiceInteractions();
Mockito.reset(pieceStorageService, pieceService, protectionService,
pieceUpdateFlowPoLineService, pieceUpdateFlowInventoryManager, basePieceFlowHolderBuilder);
Mockito.reset(pieceStorageService, pieceService, protectionService, pieceUpdateFlowPoLineService,
pieceUpdateFlowInventoryManager, basePieceFlowHolderBuilder, purchaseOrderLineService);
}

@Test
Expand Down Expand Up @@ -173,6 +174,8 @@ void shouldNotUpdateLineQuantityIfPoLineIsPackageAndShouldRunProcessInventory()
doReturn(succeededFuture(null)).when(pieceUpdateFlowInventoryManager).processInventory(any(PieceUpdateHolder.class), eq(requestContext));
doNothing().when(pieceService).receiptConsistencyPiecePoLine(any(JsonObject.class), eq(requestContext));
doReturn(succeededFuture(null)).when(pieceUpdateFlowPoLineService).updatePoLine(pieceUpdateHolderCapture.capture(), eq(requestContext));
doReturn(succeededFuture(null))
.when(purchaseOrderLineService).saveOrderLine(any(CompositePoLine.class), eq(requestContext));

//When
pieceUpdateFlowManager.updatePiece(pieceToUpdate, true, true, requestContext).result();
Expand Down Expand Up @@ -410,8 +413,8 @@ private static class ContextConfiguration {
return mock(InventoryCache.class);
}

@Bean PurchaseOrderLineService defaultPurchaseOrderLineService(RestClient restClient, InventoryCache inventoryCache) {
return spy(new PurchaseOrderLineService(restClient, inventoryCache));
@Bean PurchaseOrderLineService purchaseOrderLineService() {
return mock(PurchaseOrderLineService.class);
}

@Bean
Expand Down

0 comments on commit b672c3e

Please sign in to comment.