forked from openmrs/openmrs-esm-stock-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openmrs#77 from METS-Programme/fix/requisitionComb…
…oBox (fix) update requistion combobox to display correct text and clean up base operation
- Loading branch information
Showing
3 changed files
with
128 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/stock-operations/add-stock-operation/add-stock-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { StockOperationDTO } from "../../core/api/types/stockOperation/StockOperationDTO"; | ||
import { OperationType } from "../../core/api/types/stockOperation/StockOperationType"; | ||
|
||
const OPERATION_TYPES_FOR_DESTINATION_NAME_DELETION = [ | ||
OperationType.ADJUSTMENT_OPERATION_TYPE, | ||
OperationType.RECEIPT_OPERATION_TYPE, | ||
OperationType.STOCK_ISSUE_OPERATION_TYPE, | ||
OperationType.STOCK_TAKE_OPERATION_TYPE, | ||
OperationType.RETURN_OPERATION_TYPE, | ||
OperationType.DISPOSED_OPERATION_TYPE, | ||
OperationType.OPENING_STOCK_OPERATION_TYPE, | ||
OperationType.TRANSFER_OUT_OPERATION_TYPE, | ||
]; | ||
|
||
const OPERATION_TYPES_FOR_DESTINATION_UUID_DELETION = [ | ||
OperationType.ADJUSTMENT_OPERATION_TYPE, | ||
OperationType.DISPOSED_OPERATION_TYPE, | ||
OperationType.STOCK_TAKE_OPERATION_TYPE, | ||
OperationType.OPENING_STOCK_OPERATION_TYPE, | ||
]; | ||
|
||
export function getRequisitionStockOperations( | ||
items: Array<StockOperationDTO> = [] | ||
) { | ||
// Extract stock issued requisition UUIDs | ||
const stockIssuedRequisitionUuids = | ||
items | ||
?.filter( | ||
(item) => | ||
item.operationType === OperationType.STOCK_ISSUE_OPERATION_TYPE | ||
) | ||
.map((item) => item.requisitionStockOperationUuid) ?? []; | ||
|
||
// Filter requisition stock operations | ||
const requisitionStockOperations = | ||
items?.filter( | ||
(item) => | ||
item.operationType === OperationType.REQUISITION_OPERATION_TYPE && | ||
!stockIssuedRequisitionUuids.includes(item.uuid) | ||
) ?? []; | ||
|
||
return requisitionStockOperations; | ||
} | ||
|
||
function deleteProperties(req, properties) { | ||
properties.forEach((prop) => { | ||
delete req[prop]; | ||
}); | ||
} | ||
|
||
function shouldDeleteDestinationName(operationType) { | ||
return OPERATION_TYPES_FOR_DESTINATION_NAME_DELETION.includes(operationType); | ||
} | ||
|
||
function shouldDeleteDestinationUuid(operationType) { | ||
return OPERATION_TYPES_FOR_DESTINATION_UUID_DELETION.includes(operationType); | ||
} | ||
|
||
export function createBaseOperationPayload(model, item, operationType) { | ||
const req = Object.assign(model, item); | ||
|
||
const propertiesToDelete = [ | ||
"submitted", | ||
"cancelledByFamilyName", | ||
"atLocationName", | ||
"completedByGivenName", | ||
"cancelledBy", | ||
"submittedByFamilyName", | ||
"operationOrder", | ||
"dispatchedByGivenName", | ||
"submittedByGivenName", | ||
"returnedByGivenName", | ||
"operationNumber", | ||
"responsiblePersonFamilyName", | ||
"returnReason", | ||
"atLocationUuid", | ||
"cancelReason", | ||
"rejectedByGivenName", | ||
"reasonName", | ||
"submittedBy", | ||
"creator", | ||
"completedByFamilyName", | ||
"operationTypeName", | ||
"rejectedByFamilyName", | ||
"responsiblePerson", | ||
"creatorFamilyName", | ||
"returnedByFamilyName", | ||
"cancelledByGivenName", | ||
"operationType", | ||
"responsiblePersonGivenName", | ||
"sourceName", | ||
"rejectionReason", | ||
"completedBy", | ||
"creatorGivenName", | ||
"dispatchedByFamilyName", | ||
"uuid", | ||
]; | ||
|
||
deleteProperties(req, propertiesToDelete); | ||
|
||
if (shouldDeleteDestinationName(operationType)) { | ||
delete req.destinationName; | ||
} | ||
|
||
if (shouldDeleteDestinationUuid(operationType)) { | ||
delete req.destinationUuid; | ||
} | ||
|
||
return req; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters