Skip to content

Commit

Permalink
Merge #6673
Browse files Browse the repository at this point in the history
6673: Close requistions when stock exits complete them r=jniles a=jmcameron

Updated the Stock Exit handling so that if a stock exits completes a requisition, it will be marked as complete.

Closes #6424

**Notes**
- This will only mark a requisition as complete if all items in the requisition are handled by the stock exit.  If any items are not handled, this change will leave it marked as "Partial".
- Since it is possible for a requisition to be completed even if all items are not handled (eg, when items are lost in transit), we probably need a way to mark such requisitions as completed.   A separate issue should be created to address this issue.

**TESTING**
- Use bhima_test
- Go to:  Stock > Stock Exit
  - Make sure the source depot is: Depot Principal
  - Select from [Depot] and choose the destination depot: Depot Secondaire
  - Answer "Yes" to "Do you have a requisition slip?"
  - Select the requisition
  - Click [Submit]
  - In the main Stock Exit form, notice that some items in the order (Prednisolone) are not available
  - Click [Submit] to perform as much of the requisition as possible.
- Go to: Stock > Requisition
  - Notice that the requistion SREQ.TPA.2 is still marked Partial.
  - Edit the requistion
     - Change the quantity for the quinine to 5 (greater than 4)
     - Delete the Prednisolone
     - Click [Submit]
- Go back to: Stock > Exit
  - Repeat the process above (exiting the extra quinine to fulfill the requisition)
- Go back to:  Stock > Requisition
  - Notice the requisition is now marked Complete
 

Co-authored-by: Jonathan Cameron <jmcameron@gmail.com>
  • Loading branch information
bors[bot] and jmcameron committed Jun 13, 2022
2 parents db4101d + 03c9031 commit a930bfd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
requestor-uuid="$ctrl.requestor"
required="$ctrl.required"
disabled="$ctrl.requisitionDisabled"
disallow-completed="true"
on-select-callback="$ctrl.onSelectRequisition(requisition)">
</bh-requisition-select>

Expand Down
12 changes: 9 additions & 3 deletions client/src/js/components/bhRequisitionSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,39 @@ angular.module('bhima.components')
requisitionUuid : '<',
requestorUuid : '<?',
onSelectCallback : '&',
disallowCompleted : '@?',
required : '@?',
label : '@?',
disabled : '<?',
},
});

RequisitionSelectController.$inject = [
'StockService', 'NotifyService',
'StockService', 'NotifyService', 'bhConstants',
];

/**
* Requisition Select Controller
*
*/
function RequisitionSelectController(Stock, Notify) {
function RequisitionSelectController(Stock, Notify, bhConstants) {
const $ctrl = this;

$ctrl.$onInit = function onInit() {
$ctrl.label = $ctrl.label || 'FORM.LABELS.REQUISITION_REFERENCE';
$ctrl.required = $ctrl.required || false;
$ctrl.disallowCompleted = $ctrl.disallowCompleted || false;

const params = {};
params.requestor_uuid = $ctrl.requestorUuid;

$ctrl.disallowCompleted = false;

Stock.stockRequisition.read(null, params)
.then((requisitions) => {
$ctrl.requisitions = requisitions;
const COMPLETED = bhConstants.stockRequisition.completed_status;
$ctrl.requisitions = $ctrl.disallowCompleted
? requisitions.filter(req => req.status_id !== COMPLETED) : requisitions;
})
.catch(Notify.handleError);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function ActionRequisitionModalController(
const identifier = inventory.inventory_uuid ? inventory.inventory_uuid : inventory.uuid;
const quantity = inventory.inventory_uuid ? inventory.S_Q : inventory.quantity;

inventory.isAvailable = !!vm.availableSupplierInventories.includes(identifier);
inventory.isAvailable = vm.availableSupplierInventories && !!vm.availableSupplierInventories.includes(identifier);

if (inventory.isAvailable) {
inventory.hasEnoughQuantity = !!(vm.supplierInventoriesQuantities.get(identifier) >= quantity);
Expand Down
7 changes: 7 additions & 0 deletions server/controllers/stock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ async function depotMovement(document, params, metadata) {

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

const requistionUuid = parameters.stock_requisition_uuid;

parameters.stock_requisition_uuid = parameters.stock_requisition_uuid
? db.bid(parameters.stock_requisition_uuid) : null;

Expand Down Expand Up @@ -690,6 +692,11 @@ async function depotMovement(document, params, metadata) {
// update the quantity in stock as needed
await updateQuantityInStockAfterMovement(inventoryUuids, document.date, depotUuid);

// Update the requistion
if (parameters.stock_requisition_uuid) {
await requisition.updateStatus(requistionUuid);
}

if (!isExit) {
await shipment.updateShipmentStatusAfterEntry(document);
}
Expand Down
19 changes: 19 additions & 0 deletions server/controllers/stock/requisition/requisition.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const util = require('../../../lib/util');
const FilterParser = require('../../../lib/filter');

const REQUISITION_STATUS_PARTIAL = 3;
const REQUISITION_STATUS_COMPLETE = 6;
const REQUISITION_STATUS_EXCESSIVE = 7;

const SELECT_QUERY = `
Expand Down Expand Up @@ -270,6 +271,9 @@ exports.update = async (req, res, next) => {
dataMovementRequisition.stock_requisition_uuid, dataMovementRequisition.stock_requisition_uuid,
]);

// Assume it is complete
requisition.status_id = REQUISITION_STATUS_COMPLETE;

if (movementStatus.numberInventoryPartial > 0) {
// Partially
requisition.status_id = REQUISITION_STATUS_PARTIAL;
Expand Down Expand Up @@ -316,5 +320,20 @@ exports.deleteRequisition = async (req, res, next) => {
}
};

/**
* @function updateStatus
* @description updates the status of a requisition based
* @param {string} uuid - The uuid of the requisition
*/
async function updateStatus(uuid) {
// First get the requisition details
const balance = await getDetailsBalance(db.bid(uuid));
if (balance.items.length === 0) {
await db.exec('UPDATE stock_requisition SET status_id = ? WHERE uuid = ?', [
REQUISITION_STATUS_COMPLETE, db.bid(uuid)]);
}
}

exports.getDetails = getDetails;
exports.getDetailsBalance = getDetailsBalance;
exports.updateStatus = updateStatus;

0 comments on commit a930bfd

Please sign in to comment.