Skip to content

Commit

Permalink
OBPIH-6879 Fix rollback events issue (#4976)
Browse files Browse the repository at this point in the history
  • Loading branch information
kchelstowski authored Dec 11, 2024
1 parent 708d3cf commit a3a614d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions grails-app/domain/org/pih/warehouse/shipping/Shipment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class Shipment implements Comparable, Serializable, Historizable {
def beforeInsert() {
createdBy = AuthService.currentUser
updatedBy = AuthService.currentUser
currentEvent = mostRecentEvent
currentEvent = mostRecentSystemEvent
currentStatus = status.code
}

def beforeUpdate() {
updatedBy = AuthService.currentUser
currentEvent = mostRecentEvent
currentEvent = mostRecentSystemEvent
currentStatus = status.code
}

Expand Down Expand Up @@ -429,6 +429,14 @@ class Shipment implements Comparable, Serializable, Historizable {
return null
}

Event getMostRecentSystemEvent() {
Set<Event> systemEvents = events.findAll { EventCode.listSystemEventTypeCodes().contains(it.eventType?.eventCode) }.sort()
if (systemEvents?.size()) {
return systemEvents.first()
}
return null
}

ShipmentStatus getStatus() {
if (this.wasReceived()) {
return new ShipmentStatus([code : ShipmentStatusCode.RECEIVED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class ShipmentService {
if (shipments) {
shipments.each {
it.currentStatus = it.status.code
it.currentEvent = it.mostRecentEvent
it.currentEvent = it.mostRecentSystemEvent
if (it.save(flush: true)) {
count++
}
Expand Down Expand Up @@ -1812,7 +1812,7 @@ class ShipmentService {

void rollbackLastEvent(Shipment shipmentInstance) {

def eventInstance = shipmentInstance.mostRecentEvent
Event eventInstance = shipmentInstance.mostRecentSystemEvent

if (!eventInstance) {
throw new RuntimeException("Cannot rollback shipment status because there are no recent events")
Expand Down

0 comments on commit a3a614d

Please sign in to comment.