A Spree::StockMovement
object is created every time that a stock item moves in
or out of a stock location. This objects documents how many items were added or
removed.
The Spree::StockMovement
model has the following attributes:
stock_item_id
: The ID of theSpree::StockItem
the movement is related to.quantity
: The amount of stock items added or removed from theSpree::StockItem
'scount_on_hand
value.originator_type
andoriginator_id
: The model and ID of an object that initiated the creation of the current stock movement. For example, an originator could be an administrator (aSpree::User
) adding new stock or aSpree::Shipment
being created after an order is placed.
A typical example of a stock movement would be when a customer buys an item from your store:
- A stock item has a
count_on_hand
value of20
. - A customer buys one unit of its associated variant.
- A new
Spree::StockMovement
object is created.- It has a
quantity
of-1
. - It has a
originator_type
ofSpree::Shipment
because a new shipment triggered the movement.
- It has a
- The stock item's
count_on_hand
value is updated to19
.
Administrators can generate stock movements by changing the "Count On Hand"
value for a stock item in the solidus_backend
(on the Stock page).
However, they cannot create a stock movement directly.
Because of this, Solidus has no concept of adding to existing inventory. For example:
- A stock item has a
count_on_hand
value of7
. - A store administrator receives 25 new items to add to inventory.
- They log into the backend and change the count on hand from
7
to33
. - This creates a new
Spree::StockMovement
with a quantity of25
. (7 + 25 = 33
.)
If an administrator does not account for the units already in stock, they may enter the wrong value into the "Count On Hand" field for an item.
For example, if the administrator changes the value from 7
to 25
, then the
stock movement only documents that 18
units were added to inventory. (7 + 18 = 25
.)