Skip to content

Commit

Permalink
fix(stock): give descriptions to adjustments
Browse files Browse the repository at this point in the history
This commit creates templated descriptions to adjustments and makes
the description mandatory.

Closes Third-Culture-Software#5444.
  • Loading branch information
jniles committed Mar 2, 2021
1 parent 0855dbb commit e6b7a14
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"EXIT_SERVICE" : "Distribution to a service",
"EXIT_SERVICE_ADVANCED" : "Distribution to the service {{service}} from {{depot}}",
"EXIT_LOSS" : "Loss",
"EXIT_ADJUSTMENT" : "Negative adjustment of {{numArticles}} articles from {{depot}} by {{user}}.",
"ENTRY_ADJUSTMENT" : "Positive adjustment of {{numArticles}} articles into {{depot}} by {{user}} .",
"EXIT_INDIVIDUAL" : "Exit to Individual",
"FILE" : "Stock File",
"FLUX" : "Reason",
Expand Down
2 changes: 2 additions & 0 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
"EXIT_SERVICE_ADVANCED" : "Distribution vers le service {{service}} à partir du dépôt {{depot}}",
"EXIT_LOSS" : "Perte",
"EXIT_INDIVIDUAL" : "Distribution aux individus",
"EXIT_ADJUSTMENT" : "Ajustement négatif de {{numArticles}} articles de {{depot}} par {{user}}.",
"ENTRY_ADJUSTMENT" : "Ajustement positif de {{numArticles}} articles de dans {{depot}} par {{user}}.",
"FILE" : "Fiche de stock",
"FLUX" : "Raison",
"FROM" : "Provenance",
Expand Down
22 changes: 18 additions & 4 deletions client/src/modules/stock/adjustment/adjustment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ angular.module('bhima.controllers')
StockAdjustmentController.$inject = [
'NotifyService', 'SessionService', 'util',
'bhConstants', 'ReceiptModal', 'StockFormService', 'StockService',
'uiGridConstants',
'uiGridConstants', '$translate',
];

/**
Expand All @@ -16,7 +16,7 @@ StockAdjustmentController.$inject = [
*/
function StockAdjustmentController(
Notify, Session, util, bhConstants, ReceiptModal, StockForm,
Stock, uiGridConstants,
Stock, uiGridConstants, $translate,
) {
const vm = this;

Expand Down Expand Up @@ -207,32 +207,46 @@ function StockAdjustmentController(
}

// ================================= Submit ================================
function submit() {
function submit(form) {
let isExit;
let fluxId;

// check stock validity
checkValidity();

if (form.$invalid) { return 0; }

if (!vm.validForSubmit || !vm.adjustmentOption) { return 0; }

if (vm.Stock.hasDuplicatedLots()) {
return Notify.danger('ERRORS.ER_DUPLICATED_LOT', 20000);
}

let description;

if (vm.adjustmentOption === 'increase') {
isExit = 0;
fluxId = bhConstants.flux.FROM_ADJUSTMENT;
description = $translate.instant('STOCK.ENTRY_ADJUSTMENT', {
numArticles : vm.Stock.store.data.length,
user : Session.user.display_name,
depot : vm.depot.text,
});
} else if (vm.adjustmentOption === 'decrease') {
isExit = 1;
fluxId = bhConstants.flux.TO_ADJUSTMENT;
description = $translate.instant('STOCK.EXIT_ADJUSTMENT', {
numArticles : vm.Stock.store.data.length,
user : Session.user.display_name,
depot : vm.depot.text,
});
}

const movement = {
depot_uuid : vm.depot.uuid,
entity_uuid : vm.movement.entity.uuid,
date : vm.movement.date,
description : vm.movement.description,
description : description.concat(' -- ', vm.movement.description || ''),
is_exit : isExit,
flux_id : fluxId,
user_id : Session.user.id,
Expand Down
4 changes: 0 additions & 4 deletions server/controllers/stock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,6 @@ async function normalMovement(document, params, metadata) {
const transaction = db.transaction();
const parameters = params;

const isDistributable = !!(
(parameters.flux_id === core.flux.TO_PATIENT || parameters.flux_id === core.flux.TO_SERVICE) && parameters.is_exit
);

parameters.entity_uuid = parameters.entity_uuid ? db.bid(parameters.entity_uuid) : null;
parameters.invoice_uuid = parameters.invoice_uuid ? db.bid(parameters.invoice_uuid) : null;

Expand Down

0 comments on commit e6b7a14

Please sign in to comment.