Here's how it works
- A
Variantcan not have less than zerocount_on_hand - When a purchase invoice is created, a
LineItemis created for each item purchased - When a
LineItemis created and is awaiting payment (or if an existing one is changed to be in this status), we pass areserve_stockmessage to the associatedVariant - The code for
reserve_stockdoes the following:- Obtains a read/write row level lock on the
Variant - Reloads the
Variantfrom the database - Decrements the
count_on_handby the requested quantity
- Obtains a read/write row level lock on the
- Saves the
Variant