Skip to content

Commit

Permalink
MODORDERS-1163. Edited location should displayed in related ongoing /…
Browse files Browse the repository at this point in the history
…cancelled PO line after receiving piece from full screen form (#1000)

* MODORDERS-1163. Edited location should displayed in related ongoing / cancelled PO line after receiving piece from full screen form
  • Loading branch information
SerhiiNosko authored Aug 20, 2024
1 parent 4012cf6 commit 573134f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
23 changes: 11 additions & 12 deletions src/main/java/org/folio/helper/CheckinReceivePiecesHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@
import static org.folio.rest.jaxrs.model.Piece.ReceivingStatus.RECEIVED;
import static org.folio.rest.jaxrs.model.Piece.ReceivingStatus.UNRECEIVABLE;
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.AWAITING_RECEIPT;
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.CANCELLED;
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.FULLY_RECEIVED;
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.ONGOING;
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.PARTIALLY_RECEIVED;
import static org.folio.service.inventory.InventoryItemManager.ITEM_HOLDINGS_RECORD_ID;

Expand Down Expand Up @@ -282,15 +280,9 @@ protected Future<Map<String, List<Piece>>> updateOrderAndPoLinesStatus(Map<Strin
// Once all PO Lines are retrieved from storage check if receipt status
// requires update and persist in storage
return getPoLines(poLineIdsForUpdatedPieces, requestContext).compose(poLines -> {
// Calculate expected status for each PO Line and update with new one if required
// Skip status update if PO line status is Ongoing or Cancelled
// Calculate expected status and po line details for each PO Line and update with new one if required
List<Future<PoLine>> poLinesToUpdate = new ArrayList<>();
for (PoLine poLine : poLines) {
if (poLine.getReceiptStatus() == CANCELLED || poLine.getReceiptStatus() == ONGOING) {
logger.info("updateOrderAndPoLinesStatus:: No pieces processed - POL with {} has status CANCELLED or ONGOING", poLine.getId());
continue;
}

List<Piece> successfullyProcessedPieces = getSuccessfullyProcessedPieces(poLine.getId(), piecesGroupedByPoLine);
if (CollectionUtils.isEmpty(successfullyProcessedPieces)) {
logger.info("updateOrderAndPoLinesStatus:: No pieces processed - nothing to update for POL with {}", poLine.getId());
Expand Down Expand Up @@ -322,7 +314,10 @@ private Future<Object> saveOrderLinesBatch(Map<String, List<Piece>> piecesGroupe
.map(updatedPoLines -> purchaseOrderLineService.saveOrderLines(updatedPoLines, requestContext).map(voidResult -> {
logger.info("saveOrderLinesBatch:: {} out of {} POL updated with new status in batch", poLines.size(), piecesGroupedByPoLine.size());

updateOrderStatus.accept(poLines);
List<PoLine> notCancelledOrOngoingPoLines = updatedPoLines.stream()
.filter(poLine -> !PoLineCommonUtil.isCancelledOrOngoingStatus(poLine))
.toList();
updateOrderStatus.accept(notCancelledOrOngoingPoLines);
return null;
}));
}
Expand Down Expand Up @@ -353,8 +348,12 @@ private PoLine updateRelatedPoLineDetails(PoLine poLine,
List<Piece> piecesFromStorage,
List<Piece> byPoLine,
List<Piece> successfullyProcessed) {
ReceiptStatus receiptStatus = calculatePoLineReceiptStatus(byPoLine, successfullyProcessed, poLine);
purchaseOrderLineService.updatePoLineReceiptStatusWithoutSave(poLine, receiptStatus);
if (PoLineCommonUtil.isCancelledOrOngoingStatus(poLine)) {
logger.info("updateRelatedPoLineDetails:: Skipping updating POL '{}' status for CANCELLED or ONGOING po lines", poLine.getId());
} else {
ReceiptStatus receiptStatus = calculatePoLineReceiptStatus(byPoLine, successfullyProcessed, poLine);
purchaseOrderLineService.updatePoLineReceiptStatusWithoutSave(poLine, receiptStatus);
}

// the same check as in PieceUpdateFlowManager::updatePoLine
if (Boolean.TRUE.equals(poLine.getIsPackage()) || Boolean.TRUE.equals(poLine.getCheckinItems())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.folio.helper.BaseHelper;
import org.folio.orders.utils.HelperUtils;
import org.folio.orders.utils.PoLineCommonUtil;
import org.folio.rest.core.RestClient;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.model.Piece;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void handle(Message<JsonObject> message) {
// 2. Get PoLine for the poLineId which will be used to calculate PoLineReceiptStatus
purchaseOrderLineService.getOrderLineById(poLineIdUpdate, requestContext)
.map(poLine -> {
if (poLine.getReceiptStatus() == ReceiptStatus.CANCELLED || poLine.getReceiptStatus() == ReceiptStatus.ONGOING) {
if (PoLineCommonUtil.isCancelledOrOngoingStatus(poLine)) {
promise.complete();
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/folio/orders/utils/PoLineCommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat.OTHER;
import static org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat.PHYSICAL_RESOURCE;
import static org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat.P_E_MIX;
import static org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.ONGOING;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -291,4 +292,7 @@ private static void checkFieldsChanged(JsonPathParser oldObject, JsonPathParser
}
}

public static boolean isCancelledOrOngoingStatus(PoLine poLine) {
return poLine.getReceiptStatus() == PoLine.ReceiptStatus.CANCELLED || poLine.getReceiptStatus() == ONGOING;
}
}
46 changes: 25 additions & 21 deletions src/test/java/org/folio/rest/impl/CheckinReceivingApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ void testPostCheckinRevertPhysicalResource() {
}

@Test
void testReceiveOngoingOrder() {
void testReceiveOngoingOrderWithChangedLocation() {
logger.info("=== Test POST Receive - Ongoing PO Lines");

CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(9).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(poLines));
CompositePoLine originalPoLine = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(9).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(originalPoLine));

ReceivingCollection receivingRq = getMockAsJson(RECEIVING_RQ_MOCK_DATA_PATH + "receive-physical-ongoing.json").mapTo(ReceivingCollection.class);
receivingRq.getToBeReceived().get(0).setPoLineId(COMPOSITE_POLINE_ONGOING_ID);
Expand All @@ -378,39 +378,41 @@ void testReceiveOngoingOrder() {
List<JsonObject> pieceSearches = getPieceSearches();
List<JsonObject> pieceUpdates = getPieceUpdates();
List<JsonObject> polSearches = getPoLineSearches();
List<JsonObject> polUpdates = getPoLineUpdates();
List<JsonObject> polBatchUpdates = getPoLineBatchUpdates();

assertThat(pieceSearches, not(nullValue()));
assertThat(pieceUpdates, not(nullValue()));

assertThat(polSearches, not(nullValue()));

int expectedSearchRqQty = Math.floorDiv(receivingRq.getTotalRecords(), MAX_IDS_FOR_GET_RQ_15) + 1;

// The piece searches should be made 1 time: 1st time to get all required piece records
assertThat(pieceSearches, hasSize(expectedSearchRqQty));
// The piece searches should be made 2 times: 1st time to get all required piece records and second - get pieces by po line
assertThat(pieceSearches, hasSize(2));
assertThat(pieceUpdates, hasSize(receivingRq.getTotalRecords()));
assertThat(polSearches, hasSize(pieceIdsByPol.size()));

// check no status updates were performed and POL remained ongoing
assertThat(polUpdates, nullValue());
polSearches.forEach(pol -> {
// check no status updates were performed, but location was updated
assertThat(polBatchUpdates, hasSize(1));
polBatchUpdates.forEach(pol -> {
PoLine poLine = pol.mapTo(PoLineCollection.class).getPoLines().get(0);
assertThat(poLine.getCheckinItems(), is(false));
assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.ONGOING));
assertThat(poLine.getReceiptDate(), is(notNullValue()));

Location originalPolineLocation = originalPoLine.getLocations().get(0);
Location updatePolineLocation = poLine.getLocations().get(0);
assertThat(originalPolineLocation.getLocationId(), not(updatePolineLocation.getLocationId()));
});

// Verify no status updated for ongoing order
verifyOrderStatusUpdateEvent(0);
}

@Test
void testReceiveCancelledOrder() {
void testReceiveCancelledOrderWithChangedLocation() {
logger.info("=== Test POST Receive - Cancelled PO Lines");

CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(10).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(poLines));
CompositePoLine originalPoLine = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(10).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(originalPoLine));

ReceivingCollection receivingRq = getMockAsJson(RECEIVING_RQ_MOCK_DATA_PATH + "receive-physical-cancelled.json").mapTo(ReceivingCollection.class);
receivingRq.getToBeReceived().get(0).setPoLineId(COMPOSITE_POLINE_CANCELED_ID);
Expand All @@ -425,27 +427,29 @@ void testReceiveCancelledOrder() {
List<JsonObject> pieceSearches = getPieceSearches();
List<JsonObject> pieceUpdates = getPieceUpdates();
List<JsonObject> polSearches = getPoLineSearches();
List<JsonObject> polUpdates = getPoLineUpdates();
List<JsonObject> polBatchUpdates = getPoLineBatchUpdates();

assertThat(pieceSearches, not(nullValue()));
assertThat(pieceUpdates, not(nullValue()));

assertThat(polSearches, not(nullValue()));

int expectedSearchRqQty = Math.floorDiv(receivingRq.getTotalRecords(), MAX_IDS_FOR_GET_RQ_15) + 1;

// The piece searches should be made 1 time: 1st time to get all required piece records
assertThat(pieceSearches, hasSize(expectedSearchRqQty));
// The piece searches should be made 2 times: 1st time to get all required piece records and second - get pieces by po line
assertThat(pieceSearches, hasSize(2));
assertThat(pieceUpdates, hasSize(receivingRq.getTotalRecords()));
assertThat(polSearches, hasSize(pieceIdsByPol.size()));

// check no status updates were performed and POL remained canceled
assertThat(polUpdates, nullValue());
polSearches.forEach(pol -> {
assertThat(polBatchUpdates, hasSize(1));
polBatchUpdates.forEach(pol -> {
PoLine poLine = pol.mapTo(PoLineCollection.class).getPoLines().get(0);
assertThat(poLine.getCheckinItems(), is(false));
assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.CANCELLED));
assertThat(poLine.getReceiptDate(), is(notNullValue()));

Location originalPolineLocation = originalPoLine.getLocations().get(0);
Location updatePolineLocation = poLine.getLocations().get(0);
assertThat(originalPolineLocation.getLocationId(), not(updatePolineLocation.getLocationId()));
});

// Verify no status updated for ongoing order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@
"id": "05a95f03-eb00-4248-9f2e-2bd05957ff04",
"poLineId": "6e2b169a-ebeb-4c3c-a2f2-6233ff9c59ae",
"titleId": "9a665b22-9fe5-4c95-b4ee-837a5433c95d",
"locationId": "fcd64ce1-6995-48f0-840e-89ffa2288371",
"receivingStatus": "Expected",
"receiptDate": "2018-10-09T00:00:00.000Z",
"receivedDate": "2019-03-05T08:06:58.473+0000"
Expand All @@ -497,6 +498,7 @@
"id": "06a95f03-eb00-4248-9f2e-2bd05957ff05",
"poLineId": "1196fcd9-7607-447d-ae85-6e91883d7e4f",
"titleId": "9a665b22-9fe5-4c95-b4ee-837a5433c95d",
"locationId": "fcd64ce1-6995-48f0-840e-89ffa2288371",
"receivingStatus": "Expected",
"receiptDate": "2018-10-09T00:00:00.000Z",
"receivedDate": "2019-03-05T08:06:58.473+0000"
Expand Down

0 comments on commit 573134f

Please sign in to comment.