Skip to content

Commit

Permalink
Merge pull request #4651 from openboxes/OBPIH-6365-after-review-fixes
Browse files Browse the repository at this point in the history
OBPIH-6365 Add validation on quantity field
  • Loading branch information
awalkowiak committed Jun 7, 2024
2 parents 5957d8d + 9eb3548 commit 4e1b82f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class ImportPickCommand implements Validateable {
String lotNumber
Date expirationDate
String binLocation
Integer quantity
String quantityAsText

static transients = ['quantity']

static constraints = {
id(nullable: false, blank: false)
Expand All @@ -25,6 +27,18 @@ class ImportPickCommand implements Validateable {
})
expirationDate(nullable: true)
binLocation(nullable: true)
quantity(nullable: false, min: 0)
quantityAsText(nullable: false, validator: { val, obj ->
if (!NumberUtils.isNumber(val)) {
return ['invalid.error']
}
if (Integer.parseInt(val) < 0) {
return ['negative.error']
}
return true
})
}

Integer getQuantity() {
return NumberUtils.isNumber(this.quantityAsText) ? Integer.parseInt(this.quantityAsText) : null
}
}
2 changes: 2 additions & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,8 @@ picklistItem.quantity.label=Quantity

#Picklist import
importPickCommand.lot.scientificNotation.error=Lot numbers must not be specified in scientific notation. Please reformat field with lot number to a number format
importPickCommand.quantity.invalid.error=Invalid quantity: "{0}". Please enter a valid number.
importPickCommand.quantity.negative.error=Invalid quantity: "{0}". Quantity must not be a negative number.
importPickCommand.requisitionItem.notFound.error=Requisition item with id: {0} not found
importPickCommand.availableItem.notFound.error=The stock entry you selected: lot "{0}" and bin location "{1}" does not exist. Please review pick.
importPickCommand.availableItem.notAvailable.error=The stock entry you selected: lot "{0}" and bin location "{1}" is not available. Please review pick.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ class StockMovementService {
lotNumber: it.lotNumber,
expirationDate: it.expirationDate ? new Date(it.expirationDate) : null,
binLocation: it.binLocation,
quantity: it.quantity.isNumber() ? Integer.parseInt(it.quantity) : null
quantityAsText: it.quantity
)
}

Expand Down Expand Up @@ -1155,9 +1155,8 @@ class StockMovementService {
ApplicationTagLib g = grailsApplication.mainContext.getBean(ApplicationTagLib.class)

if (!availableItem) {

String lotNumberName = data.lotNumber ?: g.message(code: "default.label", default: "Default")
String binLocationName = data.binLocation ?: g.message(code: "default.label", default: "Default")
String lotNumberName = data.lotNumber ?: g.message(code: "default.noLotNumber.label", default: Constants.DEFAULT_LOT_NUMBER)
String binLocationName = data.binLocation ?: g.message(code: "default.noBinLocation.label", default: Constants.DEFAULT_BIN_LOCATION_NAME)
data.errors.rejectValue(
"id",
"importPickCommand.availableItem.notFound.error",
Expand All @@ -1166,9 +1165,9 @@ class StockMovementService {
)
}

if (availableItem && AvailableItemStatus.listNotAvailable.contains(availableItem.status)) {
String lotNumberName = data.lotNumber ?: g.message(code: "default.label", default: "Default")
String binLocationName = data.binLocation ?: g.message(code: "default.label", default: "Default")
if (availableItem && AvailableItemStatus.listUnavailable().contains(availableItem.status)) {
String lotNumberName = data.lotNumber ?: g.message(code: "default.noLotNumber.label", default: Constants.DEFAULT_LOT_NUMBER)
String binLocationName = data.binLocation ?: g.message(code: "default.noBinLocation.label", default: Constants.DEFAULT_BIN_LOCATION_NAME)

data.errors.rejectValue(
"id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ class AvailableItem {
enum AvailableItemStatus {
AVAILABLE, PICKED, RECALLED, HOLD, NOT_AVAILABLE

static getList() {
static list() {
[AVAILABLE, PICKED, RECALLED, HOLD, NOT_AVAILABLE]
}

static getListNotAvailable() {
static listUnavailable() {
[RECALLED, HOLD, NOT_AVAILABLE]
}
}
Expand Down

0 comments on commit 4e1b82f

Please sign in to comment.