Skip to content

Commit 23f7306

Browse files
committed
OBPIH-6969 Fixes after review
1 parent 39fa0b8 commit 23f7306

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

grails-app/controllers/org/pih/warehouse/UrlMappings.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ class UrlMappings {
805805
* Inventory API endpoints
806806
*/
807807

808-
"/api/locations/$id/inventories/import"(parseRequest: true) {
808+
"/api/facilities/$facilityId/inventories/import" {
809809
controller = { "inventoryApi" }
810810
action = "importCsv"
811811
}

grails-app/controllers/org/pih/warehouse/api/InventoryApiController.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class InventoryApiController {
2222

2323
ImportDataCommand command = new ImportDataCommand(
2424
data: CSVUtils.csvToObjects(fileData),
25-
date: new Date(),
26-
location: Location.get(params.id)
25+
date: new Date(System.currentTimeMillis() - 1000),
26+
location: Location.get(params.facilityId)
2727
)
2828

2929
inventoryImportDataService.validateData(command)

grails-app/domain/org/pih/warehouse/inventory/Transaction.groovy

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ class Transaction implements Comparable, Serializable {
179179
comment(nullable: true)
180180
// transaction date cannot be in the future
181181
transactionDate(nullable: false,
182-
validator: {
183-
value -> value <= new Date(System.currentTimeMillis() + 1000)
184-
}
185-
)
182+
validator: { value -> value <= new Date() })
186183

187184

188185
source(nullable: true,

grails-app/services/org/pih/warehouse/importer/InventoryImportDataService.groovy

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,24 +337,28 @@ class InventoryImportDataService implements ImportDataService {
337337
}
338338

339339
private InventoryItem parseInventoryItem(Product product, def lotNumberRaw, def expirationDateRaw) {
340+
Date expirationDate = parseExpirationDate(expirationDateRaw)
340341
String lotNumber = lotNumberRaw instanceof Double ? lotNumberRaw.toInteger() : lotNumberRaw
342+
return inventoryService.findAndUpdateOrCreateInventoryItem(product, lotNumber, expirationDate)
343+
}
341344

342-
if (!expirationDateRaw) {
343-
return inventoryService.findAndUpdateOrCreateInventoryItem(product, lotNumber, null)
344-
}
345-
345+
private Date parseExpirationDate(Object expirationDateRaw) {
346346
if (expirationDateRaw instanceof String) {
347347
Date expirationDate = EXPIRATION_DATE_FORMAT.parse(expirationDateRaw)
348348
Calendar calendar = Calendar.getInstance()
349349
calendar.setTime(expirationDate)
350-
return inventoryService.findAndUpdateOrCreateInventoryItem(product, lotNumber, calendar.getTime())
350+
return calendar.getTime()
351+
}
352+
353+
if (expirationDateRaw instanceof Date) {
354+
return expirationDateRaw
351355
}
352356

353357
if (expirationDateRaw instanceof LocalDate) {
354-
return inventoryService.findAndUpdateOrCreateInventoryItem(product, lotNumber, expirationDateRaw.toDate())
358+
return expirationDateRaw.toDate()
355359
}
356360

357-
return inventoryService.findAndUpdateOrCreateInventoryItem(product, lotNumber, expirationDateRaw)
361+
return null
358362
}
359363

360364
private Location parseBinLocation(String binLocationName, Location parentLocation) {

grails-app/services/org/pih/warehouse/product/ProductService.groovy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,11 +832,10 @@ class ProductService {
832832
}
833833
}
834834

835-
Product savedProduct = product.save(flush: true)
836-
if (!savedProduct) {
835+
if (!product.save(flush: true)) {
837836
throw new ValidationException("Could not save product '" + product.name + "'", product.errors)
838837
}
839-
importedProducts.add(savedProduct)
838+
importedProducts.add(product)
840839
}
841840

842841
return importedProducts

0 commit comments

Comments
 (0)