Skip to content

Commit

Permalink
Merge pull request #180 from OpenLMIS-Angola/ANGOLASUP-909-fix
Browse files Browse the repository at this point in the history
ANGOLASUP-909: fixed problem with unit swithing
  • Loading branch information
DominikNoga authored Sep 4, 2024
2 parents 68417e6 + 5378af0 commit 208056b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/shipment-view/shipment-view.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -76,7 +79,6 @@
Math.floor(currentItem.quantityShipped / currentItem.unit.factor);

shipment.lineItems[index] = currentItem;
index++;
});
});
}
Expand All @@ -91,3 +93,11 @@
});
}
})();

function findLineItemIndexByLotId(lotId, lineItems) {
var item = lineItems.find(function(lineItem) {
return lineItem.lot.id === lotId;
});

return lineItems.indexOf(item);
}

0 comments on commit 208056b

Please sign in to comment.