OBGM-408 Unable to cancel requests#4154
OBGM-408 Unable to cancel requests#4154awalkowiak merged 5 commits intofeature/upgrade-to-grails-3.3.10from
Conversation
| } | ||
|
|
||
| void deleteRequisition(StockMovement stockMovement, Requisition requisition) { | ||
| OutboundStockMovement associatedStockMovement = OutboundStockMovement.get(stockMovement.id) |
There was a problem hiding this comment.
since you fetch it once in the StockMovementService, can't you just pass it as a param instead of re-fetching it here?
kchelstowski
left a comment
There was a problem hiding this comment.
I'm wondering if associatedStockMovement is a good name - I'd name it somehow with the prefix outbound, but since I'm not the best in naming, LGTM
drodzewicz
left a comment
There was a problem hiding this comment.
After reading the article you have linked in the issue comments I now understand the problem and well... it is a headache 🥲
It's weird to me that that's how Grails works, good job on the investigation.
| shipmentService.deleteShipment(shipment) | ||
| } | ||
| requisitionService.deleteRequisition(stockMovement?.requisition) | ||
| OutboundStockMovement associatedStockMovement = OutboundStockMovement.get(stockMovement?.id) |
There was a problem hiding this comment.
I am not sure why it's done here like that. OutboundStockMovement is just a representation and a "read-only" from a view. It is not associated, nor kept in the database (OutboundStockMovement is taken from stock_movement sql view). You already have StockMovement object here, hence there is no need to pull it again as an Outbound version of it from view. What I think is required is only to set
stockMovement?.shipment = null
and
stockMovement.requisition = null
So there is no attempt to save these removed objects at the end.
There was a problem hiding this comment.
We have two domains: StockMovement and OutboundStockMovement. Both of them are looking the same, have the same id, etc. But two objects (one is created based on StockMovement, and the second is based on OutboundStockMovement) can exist independently. At the begging, I tried to delete only the shipment and requisition from the association, but I still got the error that both of them are associated.
There was a problem hiding this comment.
@alannadolny as I showed on the call, the issue is that we first pull OutboundStockMovement in the controller and then pass params.id to deleteStockMovement and there is again refetch of StockMovement. When you change the type of parameter to def to allow passing OutboundStockMovement or StockMovement to that method and pass the first object to it and do all the required cleanup, then it works properly.
There was a problem hiding this comment.
Thanks for that catch!
grails-app/services/org/pih/warehouse/inventory/StockMovementService.groovy
Outdated
Show resolved
Hide resolved
grails-app/services/org/pih/warehouse/inventory/StockMovementService.groovy
Outdated
Show resolved
Hide resolved
…dditional stockMovement
| stockMovementService.deleteStockMovement(params.id) | ||
| stockMovementService.deleteStockMovement(stockMovement) | ||
| stockMovement?.shipment = null | ||
| stockMovement?.requisition = null |
There was a problem hiding this comment.
let's do it in the service layer, before any delete() (GORM's delete) happens (in case anyone forced to add flush there, because it'd break then)
There was a problem hiding this comment.
what I mean is to add:
stockMovement?.shipment = nullto line 354 (above shipmentService.deleteShipment)
and
stockMovement?.requisition = nullto line 356 (above requisitionService.deleteRequisition(stockMovement?.requisition))
There was a problem hiding this comment.
or actually it sucks, because you then pass stockMovement.requisition which would be null to the deleteRequisition, so you should consider creating "a copy" of that object as:
Requisition requisition = stockMovement?.requisitionuse it like that:
requisitionService.deleteRequisition(requisition)but above that (between requisition and the delete call) do:
stockMovement?.requisition = nullwhich results in:
Requisition requisition = stockMovement?.requisition
stockMovement?.requisition = null
requisitionService.deleteRequisition(requisition)
Explanation: https://pihemr.atlassian.net/browse/OBGM-408?atlOrigin=eyJpIjoiYTUxMjQxZGZjYzcxNDQ5NGFiOTZlZDcxNzhmNDdmMWEiLCJwIjoiaiJ9