Skip to content

Commit

Permalink
Fix bogus warnings in Stock Exit from shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Apr 18, 2022
1 parent 0503569 commit a9ae0e3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@
"WARN_MAIN_FORM_ERRORS" : "Please enter required fields in main form!",
"WARN_NOT_CONSUMABLE_INVOICE" : "The invoice does not have any consumable items in it. No lots have been automatically filled.",
"WARN_OUT_OF_STOCK_QUANTITY" : "There is no stock of {{hrText}} to fill the requisition. These item(s) have been skipped.",
"WARN_PAST_DATE" : "You have chosen a date in the past. Only the lots available on the chosen date will be visible as well as the quantity on this date."
"WARN_PAST_DATE" : "You have chosen a date in the past. Only the lots available on the chosen date will be visible as well as the quantity on this date.",
"WARN_SOME_SHIPMENT_LOTS_EXAUSTED" : "Some lots specified in the shipment are exhausted and have been skipped below."
},
"DEPOT_DISTRIBUTION" : "Depot Distribution",
"DIRECTION": " Movement direction",
Expand Down
3 changes: 2 additions & 1 deletion client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@
"WARN_MAIN_FORM_ERRORS" : "Veuillez saisir les éléments requis dans le formulaire principal !",
"WARN_NOT_CONSUMABLE_INVOICE" : "La facture ne contient aucun article consommable. Aucun lot n'a été pourvu automatiquement.",
"WARN_OUT_OF_STOCK_QUANTITY" : "Il n'y a pas de stock de {{hrText}} pour remplir la demande. Ces éléments ont été ignorés. ",
"WARN_PAST_DATE" : "Vous avez choisi une date dans le passé. Seuls les lots disponibles à la date choisie seront visibles ainsi que la quantité à cette date."
"WARN_PAST_DATE" : "Vous avez choisi une date dans le passé. Seuls les lots disponibles à la date choisie seront visibles ainsi que la quantité à cette date.",
"WARN_SOME_SHIPMENT_LOTS_EXAUSTED" : "Certains lots spécifiés dans l'expédition sont épuisés et ont été ignorés ci-dessous."
},
"DEPOT_DISTRIBUTION" : "Distribution au dépôt",
"DIRECTION": "Direction du movement",
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/shipment/create-shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ function CreateShipmentController(
return Depot.read(vm.shipment.origin_depot_uuid);
})
.then(depot => onChangeDepot(depot))
.then(() => vm.stockForm.setLotsFromLotList(vm.shipment.lots, 'lot_uuid'))
.then(() => vm.stockForm.setLotsFromShipmentList(vm.shipment.lots, 'lot_uuid'))
.catch(Notify.handleError);
}

Expand Down
26 changes: 24 additions & 2 deletions client/src/modules/stock/StockExitForm.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function StockExitFormService(
const INFO_NO_EXIT_TYPE = 'STOCK.MESSAGES.INFO_NO_EXIT_TYPE';
const SUCCESS_FILLED_N_ITEMS = 'STOCK.MESSAGES.SUCCESS_FILLED_N_ITEMS';
const WARN_INSUFFICIENT_QUANTITY = 'STOCK.MESSAGES.WARN_INSUFFICIENT_QUANTITY';
const WARN_SOME_SHIPMENT_LOTS_EXAUSTED = 'STOCK.MESSAGES.WARN_SOME_SHIPMENT_LOTS_EXAUSTED';
const WARN_NOT_CONSUMABLE_INVOICE = 'STOCK.MESSAGES.WARN_NOT_CONSUMABLE_INVOICE';
const WARN_OUT_OF_STOCK_QUANTITY = 'STOCK.MESSAGES.WARN_OUT_OF_STOCK_QUANTITY';
const WARN_PAST_DATE = 'STOCK.MESSAGES.WARN_PAST_DATE';
Expand Down Expand Up @@ -287,11 +288,14 @@ function StockExitFormService(
this.store.clear();
};

StockExitForm.prototype.setLotsFromLotList = function setLotsFromLotList(lots, uuidKey = 'uuid') {
StockExitForm.prototype.setLotsFromShipmentList = function setLotsFromShipmentList(lots, uuidKey = 'uuid') {
const available = [];
const unavailable = [];
const insufficient = [];

const lotsInShipment = lots.map(lot => lot.lot_uuid);
let lotsUnavailable = false;

const getLot = uuid => lots.filter(lot => lot[uuidKey] === uuid);

const addLot = (item, quantity) => {
Expand All @@ -305,6 +309,13 @@ function StockExitFormService(

this._pool.list()
.forEach(lot => {

// Skip all lots that are not in the shipment
if (!lotsInShipment.includes(lot.lot_uuid)) {
lotsUnavailable = true;
return;
}

const matches = getLot(lot.lot_uuid);

if (matches.length > 0) {
Expand All @@ -314,6 +325,13 @@ function StockExitFormService(
}
});

// If the pool does not contain one of the lots that is the shipment,
// that is because there is no stock remaining for that lot. So for these
// lots we need to reconstruct the lot and add it to the unavailable list
// to improve the error messages. Also need better logic to warn when
// a lot does not have the full quantity requested.
// @todo: Add fix for this - 4/18/22 JMC

const hasNoConsumableItems = (available.length === 0 && unavailable.length === 0);
this._toggleInfoMessage(
hasNoConsumableItems,
Expand Down Expand Up @@ -382,6 +400,10 @@ function StockExitFormService(
const insufficientLabels = makeUniqueLabels(insufficient);

// finally, toggle compute the error codes
this._toggleInfoMessage(
lotsUnavailable, 'warn', WARN_SOME_SHIPMENT_LOTS_EXAUSTED, { hrText : 'Hello' },
);

this._toggleInfoMessage(
unavailable.length > 0, 'error', WARN_OUT_OF_STOCK_QUANTITY, { hrText : unavailableLabels },
);
Expand Down Expand Up @@ -568,7 +590,7 @@ function StockExitFormService(

if (depot.shipment) {
this.details.shipment_uuid = depot.shipment.uuid;
this.setLotsFromLotList(depot.shipment.lots, 'lot_uuid');
this.setLotsFromShipmentList(depot.shipment.lots, 'lot_uuid');
}
};

Expand Down

0 comments on commit a9ae0e3

Please sign in to comment.