Skip to content

Commit

Permalink
fixed #64: Packing List > Delete All does not delete shipment items f…
Browse files Browse the repository at this point in the history
…rom Unpacked Items; fixed #67: Packing List > Should display an error message if user tries to import the same item (product, lot number) within the same packing unit
  • Loading branch information
jmiranda committed May 11, 2015
1 parent 4141f5e commit 07adcc1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ class CreateShipmentWorkflowController {
on("deleteContainers") {
log.info "Delete containers from shipment " + params
try {
shipmentService.deleteContainers(params.id, params.list("containerId"), false)

def containerIds = params.list("containerId")
if (!containerIds) {
throw new ShipmentException(message: "You must select at least one container to delete", shipment:Shipment.load(params.id))
}
shipmentService.deleteContainers(params.id, containerIds, false)
flash.message = "Delete selected containers"
} catch (ShipmentException e) {
flash.message = e.message
Expand All @@ -393,7 +398,11 @@ class CreateShipmentWorkflowController {
on("deleteContainersAndItems") {
log.info "Delete containers and items from shipment " + params
try {
shipmentService.deleteContainers(params.id, params.list("containerId"), true)
def containerIds = params.list("containerId")
if (!containerIds) {
throw new ShipmentException(message: "You must select at least one container to delete", shipment:Shipment.load(params.id))
}
shipmentService.deleteContainers(params.id, containerIds, true)
flash.message = "Delete selected containers and items"
} catch (ShipmentException e) {
flash.message = e.message
Expand All @@ -407,7 +416,7 @@ class CreateShipmentWorkflowController {
log.info "Delete all containers and items from shipment " + params
try {
shipmentService.deleteAllContainers(params.id, true)
flash.message = "Delete all containers and items"
flash.message = "Successfully deleted all containers and items"
} catch (ShipmentException e) {
flash.message = e.message
} catch (Exception e) {
Expand Down Expand Up @@ -444,35 +453,6 @@ class CreateShipmentWorkflowController {

}.to("enterContainerDetails")


on("exportPackingList") {
log.info "Export packing list for shipment " + params
Shipment shipment = Shipment.get(params.id)
if (!shipment) {
throw new Exception("Could not locate shipment with ID " + params.id)
}

try {

response.contentType = "application/vnd.ms-excel"
response.setHeader 'Content-disposition', "attachment; filename=\"Shipment ${shipment?.shipmentNumber} - Packing List.xls\""

// Write the file to the response
shipmentService.exportPackingList(params.id, response.outputStream)
response.outputStream.flush();
response.outputStream.close();
flash.message = "Successfully exported all packing list items. "


} catch (ShipmentItemException e) {
[itemInstance: e.shipmentItem]
} catch (Exception e) {
log.error("Failed to export packing list due to the following error: " + e.message, e)
flash.message = "Failed to export packing list due to the following error: " + e.message
}

}.to("enterContainerDetails")

on("moveShipmentItemToContainer") {
log.info "Move shipment item to parent container " + params
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,34 +794,41 @@ class ShipmentService {
Shipment shipment = Shipment.get(id)
List containerIds = shipment?.findAllParentContainers()*.id
deleteContainers(id, containerIds, deleteItems)

// Delete all unpacked items
shipment.unpackedShipmentItems.each { shipmentItem ->
shipment.removeFromShipmentItems(shipmentItem)
shipmentItem.delete()
//shipment.save()
}

}


void deleteContainers(String id, List containerIds, boolean deleteItems) {
log.info "Delete containers " + containerIds + " from shipment " + id
Shipment shipment = Shipment.get(id)
if (shipment) {
if (!containerIds) {
throw new ShipmentException(message: "You must select at least one container to delete", shipment:shipment)
}
containerIds.each { containerId ->
Container container = Container.get(containerId)
println ("Contains items: " + container.shipmentItems)
if (!deleteItems && container.shipmentItems) {
throw new ShipmentException(message: "Cannot delete container that contains items", shipment: shipment);
}
else {
container.shipmentItems.each { shipmentItem ->
shipment.removeFromShipmentItems(shipmentItem)
shipmentItem.delete()
}
if (containerIds) {
containerIds.each { containerId ->
Container container = Container.get(containerId)
println("Contains items: " + container.shipmentItems)
if (!deleteItems && container.shipmentItems) {
throw new ShipmentException(message: "Cannot delete container that contains items", shipment: shipment);
} else {
container.shipmentItems.each { shipmentItem ->
shipment.removeFromShipmentItems(shipmentItem)
shipmentItem.delete()
}

}
shipment.removeFromContainers(container);
if (container?.parentContainer) {
container?.parentContainer?.removeFromContainers(container)
}
container.delete();
}
}
shipment.removeFromContainers(container);
if (container?.parentContainer) {
container?.parentContainer?.removeFromContainers(container)
}
container.delete();
}
}
}
}

Expand Down Expand Up @@ -1712,8 +1719,6 @@ class ShipmentService {
throw new RuntimeException("You must enter a valid Pallet if using the Box column for item " + item.productCode)
}

//throw new RuntimeException("Expected a different exception")

// If the location is a warehouse (it manages inventory) then we need to ensure that there's enough of the
// item in stock before we add it to the shipment. If the location is a supplier, we don't care.
if (location?.isWarehouse()) {
Expand All @@ -1725,6 +1730,7 @@ class ShipmentService {
}
}
}

return true;
}

Expand Down Expand Up @@ -1760,7 +1766,7 @@ class ShipmentService {

// The container assigned to the shipment item should be the one that contains the item (e.g. box contains item, pallet contains boxes)
Container container = box ?: pallet ?: null
log.info("Container " + container)
log.info("Container: " + container)

// Check to see if a shipment item already exists within the given container
ShipmentItem shipmentItem = shipment?.findShipmentItem(inventoryItem, container)
Expand All @@ -1783,10 +1789,19 @@ class ShipmentService {
shipmentItem.quantity = item.quantity;
}
}

log.info "Packing list items " + packingListItems
log.info "Shipment items " + shipment?.shipmentItems

if(packingListItems?.size() != shipment?.shipmentItems?.size()) {
throw new ShipmentException(message: "Expected ${packingListItems?.size()} packing list items, but only added ${shipment?.shipmentItems?.size()} shipment items. This usually means that you are trying to add identical items to the same pallet. Please check your packing list for duplicate items.", shipment: shipment)
}

}
} catch (ShipmentItemException e) {
log.error("Unable to import packing list items due to exception: " + e.message, e)
throw e;
throw new RuntimeException(e.message)
//throw e;

} catch (Exception e) {
log.error("Unable to import packing list items due to exception: " + e.message, e)
Expand Down

0 comments on commit 07adcc1

Please sign in to comment.