diff --git a/client/src/modules/stock/StockExitForm.service.js b/client/src/modules/stock/StockExitForm.service.js index 93b0a2f6da..3b8f4694b0 100644 --- a/client/src/modules/stock/StockExitForm.service.js +++ b/client/src/modules/stock/StockExitForm.service.js @@ -50,9 +50,11 @@ function StockExitFormService( this.cache = AppCache(cacheKey); this.details = { is_exit : 1 }; this.store = new Store({ identifier : 'uuid', data : [] }); - this.allowExpired = true; this.exitTypePredefined = false; + // this flag will filter out lots from the display that contain expired elements + this.allowExpired = true; + // this variable is private and will contain the stock for the current depot. this._pool = new Pool('lot_uuid', []); @@ -159,11 +161,7 @@ function StockExitFormService( // get the quantity in stock for this depot return Depots.getStockQuantityForDate(depotUuid, parameters) .then(stock => { - - const rawStock = this.allowExpired ? stock - : stock.filter(lot => lot.is_asset || !lot.is_expired); - - const available = rawStock + const available = stock .map(item => { const lot = new Lot(item); @@ -195,6 +193,7 @@ function StockExitFormService( StockExitForm.prototype.listLotsForInventory = function listLotsForInventory(inventoryUuid, lotUuid) { const available = this._pool.list() .filter(row => row.inventory_uuid === inventoryUuid) + .filter(row => (this.allowExpired ? true : !row.isExpired(this.details.date))) .sort((a, b) => a.expiration_date > b.expiration_date); if (lotUuid) { @@ -208,7 +207,11 @@ function StockExitFormService( }; StockExitForm.prototype.listAvailableInventory = function listAvailableInventory() { - return util.getUniqueBy(this._pool.list(), 'inventory_uuid'); + // prefilter by the expiration condition + const available = this._pool.list() + .filter(row => (this.allowExpired ? true : !row.isExpired(this.details.date))); + + return util.getUniqueBy(available, 'inventory_uuid'); }; /** diff --git a/client/src/modules/stock/exit/exit.js b/client/src/modules/stock/exit/exit.js index 25ad6e87f6..c8fe3f9e9d 100644 --- a/client/src/modules/stock/exit/exit.js +++ b/client/src/modules/stock/exit/exit.js @@ -7,9 +7,7 @@ StockExitController.$inject = [ 'StockExitFormService', 'StockEntryExitTypeService', 'uiGridConstants', 'GridExportService', 'ShipmentService', 'DepotService', '$timeout', 'BarcodeService', ]; - -/** - * @class StockExitController +/** @class StockExitController * * @description * This controller is responsible to handle stock exit module. @@ -25,6 +23,9 @@ function StockExitController( vm.stockForm = new StockForm('StockExit'); + // set allowExpired to be false + vm.stockForm.setAllowExpired(false); + vm.gridApi = {}; vm.ROW_ERROR_FLAG = bhConstants.grid.ROW_ERROR_FLAG; vm.DATE_FMT = bhConstants.dates.format; @@ -182,6 +183,13 @@ function StockExitController( break; } + // only allow expired stock if we are exiting to stock loss + if (exitType.label === 'loss') { + vm.stockForm.setAllowExpired(true); + } else { + vm.stockForm.setAllowExpired(false); + } + vm.validate(); } @@ -204,6 +212,7 @@ function StockExitController( // Handle startups from a shipment if (params.shipment) { vm.loading = true; + Shipments.readAll(params.shipment) .then(shipment => { vm.shipment = shipment;