Revert changes to computation of _immediately_usable_qty

Commit 6c16913 changed the way we compute the immediately_usable_qty: instead of using the virtual stock, we used the sum of quants without reservations. But a quant may actually be reserved and still be available (for example it may be reserved for an internal move).
Fixes https://github.com/OCA/stock-logistics-warehouse/issues/79
This commit is contained in:
Lionel Sausin
2015-09-08 18:06:12 +02:00
parent f594f72330
commit 9d97678712

View File

@@ -29,35 +29,23 @@ class ProductTemplate(models.Model):
"""
_inherit = 'product.template'
# immediately usable quantity caluculated with the quant method
@api.multi
@api.depends('virtual_available')
def _immediately_usable_qty(self):
stock_location_obj = self.env['stock.location']
internal_locations = stock_location_obj.search([
('usage', '=', 'internal')])
sublocations = self.env['stock.location']
for location in internal_locations:
sublocations += stock_location_obj.search(
[('id', 'child_of', location.id)])
for product_template in self:
products = self.env['product.product'].search([
('product_tmpl_id', '=', product_template.id)])
quant_obj = self.env['stock.quant']
quants = quant_obj.search([
('location_id', 'in', sublocations.ids),
('product_id', 'in', products.ids),
('reservation_id', '=', False)])
availability = 0
if quants:
for quant in quants:
availability += quant.qty
product_template.immediately_usable_qty = availability
"""No-op implementation of the stock available to promise.
By default, available to promise = forecasted quantity.
Must be overridden by another module that actually implement
computations."""
for product in self:
product.immediately_usable_qty = product.virtual_available
immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),
compute='_immediately_usable_qty',
string='Available to promise (quant calculation)',
string='Available to promise',
help="Stock for this Product that can be safely proposed "
"for sale to Customers.\n"
"The definition of this value can be configured to suit "