Skip to content

OBGM-408 Unable to cancel requests#4154

Merged
awalkowiak merged 5 commits intofeature/upgrade-to-grails-3.3.10from
OBGM-408
Jul 13, 2023
Merged

OBGM-408 Unable to cancel requests#4154
awalkowiak merged 5 commits intofeature/upgrade-to-grails-3.3.10from
OBGM-408

Conversation

}

void deleteRequisition(StockMovement stockMovement, Requisition requisition) {
OutboundStockMovement associatedStockMovement = OutboundStockMovement.get(stockMovement.id)
Copy link
Collaborator

@kchelstowski kchelstowski Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you fetch it once in the StockMovementService, can't you just pass it as a param instead of re-fetching it here?

@alannadolny alannadolny requested a review from kchelstowski July 10, 2023 12:45
Copy link
Collaborator

@kchelstowski kchelstowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

@drodzewicz drodzewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

@awalkowiak awalkowiak Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that catch!

stockMovementService.deleteStockMovement(params.id)
stockMovementService.deleteStockMovement(stockMovement)
stockMovement?.shipment = null
stockMovement?.requisition = null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I mean is to add:

 stockMovement?.shipment = null

to line 354 (above shipmentService.deleteShipment)
and

stockMovement?.requisition = null

to line 356 (above requisitionService.deleteRequisition(stockMovement?.requisition))

Copy link
Collaborator

@kchelstowski kchelstowski Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?.requisition

use it like that:

requisitionService.deleteRequisition(requisition)

but above that (between requisition and the delete call) do:

stockMovement?.requisition = null

which results in:

Requisition requisition = stockMovement?.requisition
stockMovement?.requisition = null
requisitionService.deleteRequisition(requisition)

@awalkowiak awalkowiak merged commit 92ca7e1 into feature/upgrade-to-grails-3.3.10 Jul 13, 2023
@awalkowiak awalkowiak deleted the OBGM-408 branch July 13, 2023 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants