Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

I can't understand stock quants

By
Grover Menacho
on 9/2/14, 2:51 PM 3,311 views

I've a question, i've read this: What's the difference between quants, lots and products?

But even now I can't understand why stock.quants exist. I've made tests, and I've read the code.

I see it as a copy of stock.move. Because available stock is based on quants. I can't understand why they stopped using stock.moves for qty_available. Please if someone understand this explain me.

 

Thanks.

4

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 9/4/14, 12:16 PM

A few reasons, namely more consistent performance long-term and FIFO/LIFO/etc.  I'm not terribly familiar with v8 yet but here's what I've gathered so far from the current RC.

stock.move transactions function almost exactly like accounting transactions, except there is no end-of-year closing system on inventory (that I'm aware of).  qty_available in 7.0 and prior is calculated using all stock.move transactions in history on that product, so as a result, performance would decrease at a relatively consistent rate.  More stock moves means more work for postgres to generate quantities.  In a large system that has been running for an extended period, calculating currenty quantity would mean aggregating years of in and out transactions.  account.account balance calculations address this problem with EOY closing/opening entries.  Calculating an account balance only means aggregating transactions as far back as the most recent opening entry, always less than a year's worth.

Quants aim to fix this by only representing stock that's currently available.  It's basically moving from O(n) complexity to (I'm guessing) O(log(n)).  As a product is sold and leaves the warehouse, the existing quant is adjusted and a new quant is generated for the customer virtual location (since stock moves are always double entry just like accounting moves).

For example, imagine 1 million WIDGETs purchased 10,000 at a time and sold one at a time.  With quants, qty_available needs to read 0~100 records.  Without quants, qty_available needs to read 100~1,000,100 records.  All of the heavy lifting is done within postgres so it's still reasonable, but over time performance will only decline.

This also makes quants perfect for enabling removal strategies like FIFO.  Quants actually care about WHICH units of a product are in stock, not just that there is some stock.  In accounting, nobody cares which specific dollar is spent, all that matters is that money moved from one account to another.  In warehousing, which specific product you're moving does matter because of expiration dates, negotiating lower cost prices, etc.  The structure of stock.move isn't really viable to handle logic like that.

Couldn't reply to the email. Roughly speaking, every new stock.move should correspond to a stock.quant being created and another being edited. The big difference is that stock calculations only depend on a portion of the entries rather than every transaction. It probably gets a bit more dicey when you're talking about fulfilling a procurement with multiple quants. I'm not sure precisely what's happening in a situation where you have two quants of 10 widgets each and sell one order of 12 widgets. Basically one of the existing quants should be entirely zeroed out (removed? converted? hidden?) and the other decreased to 8. So the stock_move and stock_quant tables might not be perfectly matched in row count, but I really don't know yet.

Brett Lehrer
on 9/4/14, 12:57 PM

Thanks I'll be checking that. It's really strange that I can delete stock.quants.... Maybe they need states? Well I'm not sure

GH Mediacloud, Grover Menacho
on 9/4/14, 6:39 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/2/14, 2:51 PM
Seen: 3311 times
Last updated: 3/16/15, 8:10 AM