The real data is quantities (weight for bulk material) added or subtracted to storage locations having a storage capacity (100 or whatever limit is specific to that one location, not the same limit across locations, 0 being the lowest possible total balance when adding together all the inventory movements). I have a script that adds a single movement as part of a transaction. If the script is called only once during the transaction, I can make my validations against the committed data only. If it is called more than once, when making the validation, I need to account for uncommitted data.
2 storage locations locA & locB where locA.maxCapacity <> locB.maxCapacity
- locA is empty
- locB is empty
- receiving x kg into locA (weight and location are parameters my script receives)
- receiving y kg into locB
This is easy, I compare the qty received in with the balance of the location specified in the parameter. If adding the 2 together does not bust the max capacity of the location I’m dealing with, I process the information, if not I throw back an error.
- receiving z kg into locA
- receiving c kg into locB
- receiving b kg into locB
- shipping out r kg from locB
- receiving s kg into locB
Here, for location A, comparing only against committed data is ok. For location B, script call #3 requires me to account for call #2 when comparing with the balance because the impact of that reception is not committed and does not show in the balance. The same concept applies when shipping out, r kg may exceed the committed balance, but that is still ok if the quantities received in calls #2 & #3 combined with the balance let me cover for r kg. Then again, on call #5, to know if s kg will bust the location capacity, I need to account for all the uncommitted data, but not the uncommitted data that pertains to location A.
Again, I do not have control on how my script is going to be called. Some of this also happens in my own code because some operations ask me to generate movements that are “adjustments” to the inventory as part of the operation within the same transaction.
All of this has additional layers because the structure also has different materials and different owners each having their own balance of a given material (like bank accounts with different currencies). That said, a given location can only store one material at a time, but it can change if the location is emptied and “reset” to contain a new material.