Skip to content

Commit

Permalink
fix(stock): make "at risk of expiration" flag work
Browse files Browse the repository at this point in the history
This fix restores the functionality of the "at risk of expiration" flag
on the articles in stock registry.  It does not affect the API, just the
internal calculations.

In addition, we also changed the behavior of the articles in stock
action dropdown menu so the link to the stock lots now filters on the
depot and time period in question.

Closes Third-Culture-Software#5422.
  • Loading branch information
jniles committed Feb 26, 2021
1 parent 916d394 commit 9445799
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ "STOCK" : {
{
"STOCK" : {
"ALERT" : "Alert",
"ADJUSTMENT" : "Adjustment",
"ADJUSTMENT_TYPE" : "Adjustment Type",
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/stock/StockFilterer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function StockFiltererService(Filters, AppCache, $httpParamSerializer, Languages
{ key : 'is_expiry_risk', label : 'STOCK.STATUS.IS_IN_RISK_OF_EXPIRATION' },
{ key : 'tag_uuid', label : 'TAG.LABEL' },
{ key : 'tags', label : 'TAG.LABEL' },
{ key : 'show_only_risky', label : 'STOCK.LOTS.SHOW_ONLY_RISKY' },
{ key : 'show_only_risky', label : 'LOTS.SHOW_ONLY_RISKY_LOTS' },
{ key : 'stock_requisition_uuid', label : 'FORM.LABELS.REQUISITION_REFERENCE' },
{
key : 'dateFrom', label : 'FORM.LABELS.DATE', comparitor : '>', valueFilter : 'date',
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/inventories/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function StockInventoriesController(
}

function setStatusFlag(item) {

item.noAlert = !item.hasRiskyLots && !item.hasNearExpireLots && !item.hasExpiredLots;
item.alert = item.hasExpiredLots;
item.warning = !item.hasExpiredLots && (item.hasNearExpireLots || item.hasRiskyLots);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<a data-method="stock-lots" href
ui-sref="stockLots({
filters : [
{ key : 'period', value : 'allTime', cacheable: false },
{ key : 'depot_uuid', value : row.entity.depot_uuid, displayValue : row.entity.depot_text, cacheable: false},
{ key : 'inventory_uuid', value : row.entity.inventory_uuid, displayValue: row.entity.text, cacheable: false }
]})">
<i class="fa fa-cubes"></i> <span translate>INVENTORY.VIEW_LOTS_IN_STOCK</span>
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ function computeLotIndicators(inventories) {
lot.expiration_date = '';
}

lot.exhausted = lot.quantity === 0;
lot.exhausted = lot.quantity <= 0;
lot.expired = !lot.exhausted && (lot.expiration_date < today);

// algorithm for tracking the stock consumption by day
Expand Down
22 changes: 13 additions & 9 deletions server/controllers/stock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,21 +832,25 @@ async function listInventoryDepot(req, res, next) {
const hasSameDepot = lots[j].depot_uuid === inventories[i].depot_uuid;
const hasSameInventory = lots[j].inventory_uuid === inventories[i].inventory_uuid;
if (hasSameDepot && hasSameInventory) {

// NOTE(@jniles): at this point, we've called computeLotIndicators() in the
// core.getLotsDepot() function. This means we can use all the flags defined
// in that function to compute those here.
const lot = lots[j];
if (lot.quantity <= 0) {
// lot exhausted
} else if (lot.lifetime < 0) {
// Equivalent to: lot.quantity > 0 && lot.lifetime < 0

if (lot.exhausted) {
// skip exhausted lots
} else if (lot.expired) {
hasExpiredLots = true;
expiredLotsQuantity += lot.quantity;
} else if (lot.IS_IN_RISK_EXPIRATION) {
// Equivalent to: lot.quantity > 0 && lot.lifetime >= 0 && lot.IS_IN_RISK_EXPIRATION
} else if (lot.near_expiration) {
hasNearExpireLots = true;
nearExpireLotsQuantity += lot.quantity;
} else if (lot.S_RISK <= 0) {
// Equivalent to: lot.quantity > 0 && lot.lifetime >= 0 && lot.S_RISK <= 0

// flag if any lots are at risk of running out
} else if (lot.S_RISK_QUANTITY > 0) {
hasRiskyLots = true;
riskyLotsQuantity += lot.quantity;
riskyLotsQuantity += lot.S_RISK_QUANTITY;
}
}
}
Expand Down

0 comments on commit 9445799

Please sign in to comment.