Skip to content

Commit

Permalink
Fix issue with stock exits without permissions for destination depot
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Aug 31, 2022
1 parent 825032f commit 64c8d16
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 48 deletions.
30 changes: 16 additions & 14 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,37 @@
"TRACK_CONSUMPTION":"Track consumption",
"TRACK_EXPIRATION":"Track expiration",
"ERRORS" : {
"NO_ROWS" : "Must have at least one row in the grid.",
"MISSING_LOT_NAME" : "Missing Lot Identifier",
"INVALID_LOT_QUANTITY" : "Invalid Lot Quantity",
"INVALID_LOT_EXPIRATION" : "Invalid Lot Expiration Date",
"EXCESSIVE_QUANTITY": "Excessive Quantity",
"INVALID_GLOBAL_QUANTITY" : "Invalid Global Lot's Quantity",
"INVALID_LOT_EXPIRATION" : "Invalid Lot Expiration Date",
"INVALID_LOT_QUANTITY" : "Invalid Lot Quantity",
"INVALID_PERIOD" : "The date set is in the wrong period",
"INVALID_QUANTITY_NEGATIVE" : "Negative quantity",
"INVALID_RANGE" : "Range error, the start date cannot be greater than the end date",
"LOT_ROW_WITH_ERRORS" : "Lot line contains invalid data",
"EXCESSIVE_QUANTITY": "Excessive Quantity",
"LOT_EXPIRED" : "Lot {{label}} is expired. Its expiration date ({{expiration_date | date }}) is before the selected date.",
"LOT_MISSING_INVENTORY_INFO" : "Lot {{label}} is missing inventory information. Please select an inventory item to continue.",
"LOT_MISSING_LOT_INFO" : "Lot {{ uuid }} is missing lot information. Please select a lot label to continue.",
"LOT_NEGATIVE_QUANTITY" : "Lot {{label}} has a negative quantity.",
"LOT_OVERCONSUMPTION" : "Lot {{label}} is over-used. Expected {{quantity}} {{unit}} to be less than {{_quantity_available}} {{unit}}.",
"LOT_QUANTITY_OVER_GLOBAL": "Total lot quantity is more than the global quantity",
"LOT_ROW_WITH_ERRORS" : "Lot line contains invalid data",
"LOT_UNUSED" : "Lot {{label}} isn't used (0 {{unit}} selected). Please specify a quantity to continue.",
"MISSING_LOT_NAME" : "Missing Lot Identifier",
"MISSING_LOT_UNIT_COST": "A non-negative value is required for lot unit cost",
"NO_PERMISSION_ORIGIN_DEPOT": "ERROR! You do not have permission to access origin depot '{{ depot }}'!",
"NO_PERMISSION_DESTINATION_DEPOT": "ERROR! You do not have permission to access destination depot '{{ depot }}'!",
"NO_ROWS" : "Must have at least one row in the grid.",
"OVERCONSUMED_INVENTORIES": "Over-consumed inventories",
"OVERCONSUMED_INVENTORIES_DESCRIPTION": "<strong>{{ text }}</strong> with batch number <strong>{{label}}</strong>, actually only has <strong>{{ quantityAvailable }} {{ unit_type }}</strong> consumption of <strong>{{ quantity }} {{ unit_type }}</strong> will result in a negative inventory quantity",
"PLEASE_CHECK_EXPIRY_DATE": "Please check the expiration date",
"POORLY_FORMALIZED_DATE_RANGE": "Poorly formalized date range: one consumption period must not be contained in another",
"PROBLEMATIC_ADJUSTMENT": "Problematic Adjustment",
"PROBLEMATIC_ADJUSTMENT_DESCRIPTION": "Changing the quantity of <strong>{{ text }}</strong> in lot label <strong>{{label}}</strong> from <strong>{{ old_quantity }}</strong> to <strong>{{ quantity }}</strong> will result in a negative inventory quantity, The quantity currently in stock is <strong>{{ quantityAvailable }}</strong>",
"POORLY_FORMALIZED_DATE_RANGE": "Poorly formalized date range: one consumption period must not be contained in another",
"QUANTITY_CONSUMED_LOWER" : "Total quantity consumed is lower than the global quantity consumed",
"QUANTITY_CONSUMED_OVER_GLOBAL" : "Total quantity consumed is more than the global quantity consumed",
"QUANTITY_LOST_LOWER" : "Total quantity lost is lower than the global quantity lost",
"QUANTITY_LOST_OVER_GLOBAL" : "Total quantity lost is more than the global quantity lost",
"UNINITIALISED" : "This grid row is empty and uninitialized. Please remove it to submit.",
"LOT_EXPIRED" : "Lot {{label}} is expired. Its expiration date ({{expiration_date | date }}) is before the selected date.",
"LOT_MISSING_INVENTORY_INFO" : "Lot {{label}} is missing inventory information. Please select an inventory item to continue.",
"LOT_MISSING_LOT_INFO" : "Lot {{ uuid }} is missing lot information. Please select a lot label to continue.",
"LOT_NEGATIVE_QUANTITY" : "Lot {{label}} has a negative quantity.",
"LOT_OVERCONSUMPTION" : "Lot {{label}} is over-used. Expected {{quantity}} {{unit}} to be less than {{_quantity_available}} {{unit}}.",
"LOT_UNUSED" : "Lot {{label}} isn't used (0 {{unit}} selected). Please specify a quantity to continue."
"UNINITIALISED" : "This grid row is empty and uninitialized. Please remove it to submit."
},
"ENTRY_ADJUSTMENT" : "Positive adjustment of {{numArticles}} articles into {{depot}} by {{user}} .",
"EXIT" : "Stock Exit",
Expand Down
28 changes: 15 additions & 13 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,37 @@
"TRACK_CONSUMPTION":"Suivre la consommation",
"TRACK_EXPIRATION":"Suivre l'expiration",
"ERRORS" : {
"NO_ROWS" : "Vous devez avoir au moins une ligne dans le grid.",
"MISSING_LOT_NAME" : "Identifiant de lot manquant",
"INVALID_LOT_QUANTITY" : "Quantité de lot invalide",
"EXCESSIVE_QUANTITY": "Quantité excessive",
"INVALID_GLOBAL_QUANTITY" : "Quantité globale des lots invalide",
"INVALID_LOT_EXPIRATION" : "Date d'expiration invalide",
"INVALID_LOT_QUANTITY" : "Quantité de lot invalide",
"INVALID_PERIOD" : "La date définie est dans la mauvaise période",
"INVALID_QUANTITY_NEGATIVE" : "Quantité négative",
"INVALID_RANGE" : "Erreur de plage, la date du début ne peut être supérieur à la date de fin",
"LOT_ROW_WITH_ERRORS" : "Données invalide dans certaines lignes de lot ",
"EXCESSIVE_QUANTITY": "Quantité excessive",
"LOT_EXPIRED" : "Lot {{label}} est expiré. Sa date d'expiration ({{expiration_date | date }}) précède la date selectionnée.",
"LOT_MISSING_INVENTORY_INFO" : "Lot {{label}} manque les informations d'inventaire. Veuillez selectionner l'inventaire pour continuer.",
"LOT_MISSING_LOT_INFO" : "Lot {{ uuid }} manque les informations de lot. Veuillez selectionner le libellé du lot pour continuer.",
"LOT_NEGATIVE_QUANTITY" : "Lot {{label}} a une quantité négative.",
"LOT_OVERCONSUMPTION" : "Lot {{label}} est sur-utilisé. Attendu {{quantity}} {{unit}} doit être moins que {{_quantity_available}} {{unit}}.",
"LOT_QUANTITY_OVER_GLOBAL": "La quantité totale des lots dépasse la quantity globale fournie",
"LOT_ROW_WITH_ERRORS" : "Données invalide dans certaines lignes de lot ",
"LOT_UNUSED" : "Lot {{label}} n'est pas utilisé (0 {{unit}} séléctionné). Veuillez spécifier une quantité pour continuer.",
"MISSING_LOT_NAME" : "Identifiant de lot manquant",
"MISSING_LOT_UNIT_COST": "Une valeur non négative est requise pour le coût unitaire du lot",
"NO_PERMISSION_ORIGIN_DEPOT": "ERREUR ! Vous n'avez pas la permission d'accéder au dépôt d'origine '{{ depot }}' !",
"NO_PERMISSION_DESTINATION_DEPOT": "ERREUR ! Vous n'avez pas l'autorisation d'accéder au dépôt de destination '{{ depot }}' !",
"NO_ROWS" : "Vous devez avoir au moins une ligne dans le grid.",
"OVERCONSUMED_INVENTORIES": "Inventaires surconsommés",
"OVERCONSUMED_INVENTORIES_DESCRIPTION": "La sortie de stock de l'inventaire <strong>{{ text }}</strong> dans lot <strong>{{label}}</strong> de <strong>{{ quantity }} {{ unit_type }}</strong> entraînera une quantité d'inventaire négative car la quantité actuellement en stock n'est que de <strong>{{ quantityAvailable }} {{ unit_type }}</strong>",
"PLEASE_CHECK_EXPIRY_DATE": "Veuillez vérifier la date d'expiration",
"POORLY_FORMALIZED_DATE_RANGE": "Plages des dates males formalisées: une période de consommation ne doit pas être contenue dans une autre",
"PROBLEMATIC_ADJUSTMENT": "Ajustement problematique",
"PROBLEMATIC_ADJUSTMENT_DESCRIPTION": "L'ajustement de la quantité de l'inventaire <strong>{{ text }}</strong> dans le lot <strong>{{label}}</strong> de <strong>{{ old_quantity }}</strong> à <strong>{{ quantity }}</strong> entraînera une quantité d'inventaire négative, la quantité actuellement en stock n'est que de <strong>{{ quantityAvailable }}</strong>",
"POORLY_FORMALIZED_DATE_RANGE": "Plages des dates males formalisées: une période de consommation ne doit pas être contenue dans une autre",
"QUANTITY_CONSUMED_LOWER" : "La quantité totale consommé est inférieure à la quantity globale consommée",
"QUANTITY_CONSUMED_OVER_GLOBAL" : "La quantité totale consommé dépasse la quantity globale consommée",
"QUANTITY_LOST_LOWER" : "La quantité totale perdue est inférieure à la quantity globale perdue",
"QUANTITY_LOST_OVER_GLOBAL" : "La quantité totale perdue dépasse la quantity globale perdue",
"UNINITIALISED" : "Cette ligne de grille est vide et non initialisée. Veuillez le supprimer pour le soumettre.",
"LOT_EXPIRED" : "Lot {{label}} est expiré. Sa date d'expiration ({{expiration_date | date }}) précède la date selectionnée.",
"LOT_MISSING_INVENTORY_INFO" : "Lot {{label}} manque les informations d'inventaire. Veuillez selectionner l'inventaire pour continuer.",
"LOT_MISSING_LOT_INFO" : "Lot {{ uuid }} manque les informations de lot. Veuillez selectionner le libellé du lot pour continuer.",
"LOT_NEGATIVE_QUANTITY" : "Lot {{label}} a une quantité négative.",
"LOT_OVERCONSUMPTION" : "Lot {{label}} est sur-utilisé. Attendu {{quantity}} {{unit}} doit être moins que {{_quantity_available}} {{unit}}.",
"LOT_UNUSED" : "Lot {{label}} n'est pas utilisé (0 {{unit}} séléctionné). Veuillez spécifier une quantité pour continuer."
"UNINITIALISED" : "Cette ligne de grille est vide et non initialisée. Veuillez le supprimer pour le soumettre."
},
"ENTRY_ADJUSTMENT" : "Ajustement positif de {{numArticles}} articles de dans {{depot}} par {{user}}.",
"EXIT" : "Sortie de stock",
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/stock/exit/modals/findDepot.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<bh-loading-button
disabled="!$ctrl.depotSelected()"
loading-state="FindForm.$loading">
loading-state="$ctrl.loading">
<span translate>FORM.BUTTONS.SUBMIT</span>
</bh-loading-button>
</div>
Expand Down
56 changes: 36 additions & 20 deletions client/src/modules/stock/exit/modals/findDepot.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ angular.module('bhima.controllers')
StockFindDepotModalController.$inject = [
'$uibModalInstance', 'DepotService', 'NotifyService', 'data',
'SessionService', 'RequisitionHelperService', 'ShipmentService',
'ModalService', '$translate',
];

function StockFindDepotModalController(
Instance, Depot, Notify, Data, Session, RequisitionHelpers, Shipments,
Instance, Depot, Notify, Data,
Session, RequisitionHelpers, Shipments,
Modal, $translate,
) {
const vm = this;

Expand All @@ -16,34 +19,47 @@ function StockFindDepotModalController(
// global
vm.selected = {};
vm.depot = Data.depot;
vm.loading = false;

// bind methods
vm.submit = submit;
vm.cancel = cancel;

// Make sure this user has permissions to exit from this depot
if (enableStrictDepotDistribution) {
Depot.read(Data.depot.uuid)
.then(depot => {
// forbid to distribute to the same depot
vm.depots = extractDepotFromCollection(Data.depot.uuid, depot.distribution_depots);
})
.catch(Notify.handleError);
} else {
Depot.read()
.then(depots => {
// set defined the previous selected depot
if (Data.entity_uuid) {
const currentDepot = depots.find(item => item.uuid === Data.entity_uuid);
vm.selected = currentDepot || {};
Depot.read(Data.depot.uuid, { only_user : true })
.then(originDepot => {
if (!originDepot) {
Instance.close();
const errMsg = $translate.instant('STOCK.ERRORS.NO_PERMISSION_ORIGIN_DEPOT',
{ depot : vm.depot.text });
Modal.alert(errMsg);
}

// forbid to distribute to the same depot
vm.depots = extractDepotFromCollection(Data.depot.uuid, depots);
})
.catch(Notify.handleError);
});
}

function extractDepotFromCollection(depotUuid, collection) {
// Load the depots
Depot.read()
.then(depots => {
// NOTE: We do not care about the 'enableStrictDepotDistribution' flag for the
// the destination depot since the user doing the stock exit (here) does
// not necessarily need permission to access the destination depot.

// set the previous selected depot (if given)
if (Data.entity_uuid) {
const currentDepot = depots.find(item => item.uuid === Data.entity_uuid);
vm.selected = currentDepot || {};
}

// Prevent distribution to the same depot
vm.depots = removeDepotFromCollection(Data.depot.uuid, depots);
})
.finally(() => {
vm.loading = false;
})
.catch(Notify.handleError);

function removeDepotFromCollection(depotUuid, collection) {
return collection.filter(depot => depot.uuid !== depotUuid);
}

Expand Down

0 comments on commit 64c8d16

Please sign in to comment.