OCA/stock-logistics-warehouse — pull request #5 by clonedagain (2014-07-29 09:37:19+00:00)
Title: Generic module to compute the stock quantity available to promise

The "quantity available to promise" is the quantity of a product that you can commit to deliver to a customer.
Depending on the business, it may depend on expected deliveries, manufacturing, expected sales, or many other parameters.
To handle this concept in a modular and configurable way, @lbellier and I add a generic module to compute the stock quantity available to promise using several optional implementations.

Changes to module immediately_usable_qty
---
The existing module stock_available_immediately is turned into the first optional implementation.
stock_available_immediately is rewritten to compute "virtual - incoming" instead of "real - outgoing", which should be mostly the same except for rounding.
The field name "immediately_usable_qty" is unchanged for compatibility, but the field is now called "Available to promise" in the views and help texts (this wording seems more widespread).

Code trick: function field modularity
---
By default function fields are not very modular (you need to redefine the whole field to override the method). stock_available takes care of this by making the function fields call the pool instead, so that stock_available_immediately and other future implementations need only override the function _product_available.

Code trick: context to override the virtual stock
---
The new module also has a context trick that lets it return the value of the stock available to promise in the field "virtual stock". This lets future sub-modules change the behavior of modules that were written to use the virtual stock, to use the new value instead with minimal impact.