OBGM-560 Fix association between transaction and shipment while rollbacking and fix refresh product availability when deleting outbound return#4145
Conversation
| class Order implements Serializable { | ||
|
|
||
| def beforeInsert = { | ||
| def beforeInsert() { |
There was a problem hiding this comment.
closures for events work also in Grails 3, but just the code is "gray", so since I was "touching" this code while debugging, I decided to change it to the methods, to follow the Grails 3 convention
There was a problem hiding this comment.
If I understand correctly this change to closures doesn't affect the functionality of the event and you changed it because it is a preferable way to do it in grails 3 and not because it fixes something, right?
There was a problem hiding this comment.
@drodzewicz yes, exactly. It is working, but if we take a look at grails 3 docs, they (events) are specified as methods:
https://docs.grails.org/3.0.x/guide/GORM.html#eventsAutoTimestamping
As this ticket drove me nuts, a little description (as always 😄 ):
1. rollback problem - we have a bidirectional relationship between
TransactionandShipment. The problem there was that we were not assigningoutgoingShipmentto theTransactioninstance, we were only doing it for one direction, so for shipment like:shipmentInstance.addToOutgoingTransactions(debitTransaction)For correct bidirectional relationships, we have to add it for both sides.
Grails is that clever, that when doing
addToOutgoingTransactions, it was automatically assigning theoutgoingShipmentfor thedebitTransactionalso, but it was not persisted. In grails 1 it was working due to OSIV, that was catching those "dirty" changes and here, it doesn't work, because we saved thedebitTransactiona few lines above.What also fixed the issue was removing this:
because then, the
debitTransactionwas saved at the end of the session and theoutgoingShipmentset by the:shipmentInstance.addToOutgoingTransactions(debitTransaction)was caught.
We could either change it to
validate()and let Grails do the work with associations, but I think the path I went with assigning it explicitly is a more proper solution.2. quantity available not updating when deleting the shipment:
This drove me nuts.... since we were refreshing product availability asynchronously and the session that was deleting picklist items was not yet flushed and the
productAvailabilityServicewas creating its own session and transaction, it didn't know "what is going on" in the first session, that is deleting the entities.... so it was thinking that picklist item is still in the DB (because the deletion was still in batch in first session)....After long debugging it turned out, that we have missing properties for product availability jobs, which was the delay.....
Adding the delay, fixed the issue, because the first session "managed" to finish and to be flushed before the second session (from the job) initialized.