From 5378af0fc04cba65c15a19379d2b2407ae5f207e Mon Sep 17 00:00:00 2001 From: DominikNoga Date: Wed, 4 Sep 2024 16:10:19 +0200 Subject: [PATCH] ANGOLASUP-909: fixed problem with unit swithing --- src/shipment-view/shipment-view.routes.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/shipment-view/shipment-view.routes.js b/src/shipment-view/shipment-view.routes.js index 10c0b44..4f2d1f7 100644 --- a/src/shipment-view/shipment-view.routes.js +++ b/src/shipment-view/shipment-view.routes.js @@ -62,10 +62,13 @@ unitOfOrderableService) { return unitOfOrderableService.getAll().then(function(response) { var unitsOfOrderable = response.content ? response.content : response; - var index = 0; if (shipment.lineItems && shipment.lineItems.length > 0) { stockCardSummaries.forEach(function(summary) { summary.canFulfillForMe.forEach(function(canFulfill) { + var index = findLineItemIndexByLotId(canFulfill.lot.id, shipment.lineItems); + if (index === -1) { + return; + } var unitId = canFulfill.unitOfOrderable.id; var currentItem = angular.copy(shipment.lineItems[index]); currentItem.unitOfOrderableId = unitId; @@ -76,7 +79,6 @@ Math.floor(currentItem.quantityShipped / currentItem.unit.factor); shipment.lineItems[index] = currentItem; - index++; }); }); } @@ -91,3 +93,11 @@ }); } })(); + +function findLineItemIndexByLotId(lotId, lineItems) { + var item = lineItems.find(function(lineItem) { + return lineItem.lot.id === lotId; + }); + + return lineItems.indexOf(item); +}