From f748a8b5ba3fd6874a8407ec617c692d81559a71 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Fri, 1 Apr 2022 11:32:44 +0200 Subject: [PATCH] Prevent expired stock from being added to shipments --- client/src/modules/shipment/create-shipment.js | 2 ++ client/src/modules/stock/StockExitForm.service.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client/src/modules/shipment/create-shipment.js b/client/src/modules/shipment/create-shipment.js index cb350a3914..81ca67c688 100644 --- a/client/src/modules/shipment/create-shipment.js +++ b/client/src/modules/shipment/create-shipment.js @@ -20,7 +20,9 @@ function CreateShipmentController( vm.existingShipmentUuid = existingShipmentUuid; vm.isCreateState = $state.params.isCreateState; + vm.stockForm = new StockForm('ShipmentForm'); + vm.stockForm.setAllowExpired(false); const gridFooterTemplate = `
diff --git a/client/src/modules/stock/StockExitForm.service.js b/client/src/modules/stock/StockExitForm.service.js index cab7b8ff79..724e06d295 100644 --- a/client/src/modules/stock/StockExitForm.service.js +++ b/client/src/modules/stock/StockExitForm.service.js @@ -48,6 +48,7 @@ function StockExitFormService( this.cache = AppCache(cacheKey); this.details = { is_exit : 1 }; this.store = new Store({ identifier : 'uuid', data : [] }); + this.allowExpired = true; // this variable is private and will contain the stock for the current depot. this._pool = new Pool('lot_uuid', []); @@ -58,6 +59,14 @@ function StockExitFormService( this._messages = new Map(); } + /** + * Set flag to allow or disable expired stock + * @param {boolean} flag + */ + StockExitForm.prototype.setAllowExpired = function setAllowExpired(flag) { + this.allowExpired = flag; + }; + StockExitForm.prototype._toggleInfoMessage = function _toggleInfoMessage( shouldShowMsg, msgType, msgText, msgKeys = {}, ) { @@ -140,7 +149,10 @@ function StockExitFormService( return Depots.getStockQuantityForDate(depotUuid, parameters) .then(stock => { - const available = stock + const rawStock = this.allowExpired ? stock + : stock.filter(lot => !lot.is_asset && !lot.is_expired); + + const available = rawStock .map(item => { const lot = new Lot(item);