--
Each inventory unit record tracks one "physical" item in an order. It's used to track individual items against an order, similar to how line_items does it, except inventory units are for each individual item, rather than for each unique grouping of items. The inventory_units table is only used for tracking items that have already been ordered by people, not items that could *potentially* be ordered in.Spree doesn't have a way to track stock receipt at this time. It's something that, I think, would be useful. For instance, people would want to know that last week they received a shipment of 20 items and now they're all gone, so this week they better order more. That kind of thing.I don't think you would be able to use inventory_units for the purpose you want to.
---Now for a "short" rant about inventory tracking in Spree:
When you're receiving stock, you're going to be incrementing the count_on_hand for the product or variant. I personally am not happy with this workflow for a number of reasons.First: when you receive stock, I assume that you would know how much of that stock you're receiving. Let's say you receive 20 Blue Superman T-Shirts. Therefore, you're wanting to add 20 to the total of Blue Superman T-Shirts you already have in stock. To do that, you go into the product/variant admin screen, find the amount is 39 and then do some mental arithmetic and determine that 20+39=59, unless you're having a really bad day and then it's some other number.Secondly: after you enter this number and hit enter, if someone else as either a) edited this number in the admin screen too for whatever reason or b) bought the product from the store, you're going to have a bad time because (and this is only recently), you'll have an ActiveRecord::StaleObjectError raised and that's no fun. This is because you'll be attempting to update the product/variant record with a new count_on_hand for an old lock_version, and AR will be all "nah-uhhhh" and then you may cry.Thirdly: If two people buy the same product/variant at precisely the same second, Spree will query the Variant record, find the count_on_hand value and then decrement it *in Ruby and then save that value back to the database*. If you have two Ruby processes doing this at the same time, chances are the count is going to be off-by-1'd, which can lead to more drama. This problem could probably be solved by using serialisable transactions within the database... but I don't know whether or not that's 100% correct because I've not had time to look into it.
---So.Inventory is not a completely solved problem within Spree... yet. It's something that would be good to work on, but with the smallness of our team and the plethora of other things we've got going on, we haven't had time to look into improving how inventory is dealt with by Spree. imo, it needs fixing and therefore, one day, it'll get it.
--
--
--
Nate - FYI we're working a big refactor of shipping and inventory for the 2.0 release.We'll essentially be including your stock ledger functionality (we're currently calling it Stock Movements), it will also include optional multi-warehouse support, and checkout shipment splitting.We'll probably do a blog post with the details once the design has stabilised.
--