diff --git a/stock_available/product.py b/stock_available/product.py
index 1a3b72a59..dd7c6bb93 100644
--- a/stock_available/product.py
+++ b/stock_available/product.py
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+#-*- coding: utf-8 -*-
##############################################################################
#
# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
@@ -24,28 +24,41 @@ from openerp.addons import decimal_precision as dp
class ProductTemplate(models.Model):
"""Add a field for the stock available to promise.
-
Useful implementations need to be installed through the Settings menu or by
installing one of the modules stock_available_*
"""
_inherit = 'product.template'
+ # immediately usable quantity caluculated with the quant method
+ @api.multi
@api.depends('virtual_available')
- def _product_available(self):
- """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
+ def _immediately_usable_qty(self):
+ stock_location_obj = self.env['stock.location']
+ internal_locations = stock_location_obj.search([
+ ('usage', '=', 'internal')])
+ sublocation_ids = []
+ for location in internal_locations:
+ sublocation_ids.append(self.env['stock.location'].search(
+ [('id', 'child_of', location.id)]).ids)
+ for product_template in self:
+ quant_obj = self.env['stock.quant']
+ quants = quant_obj.search([
+ ('location_id', 'in', sublocation_ids),
+ ('product_id', 'in', product_template.ids),
+ ('reservation_id', '=', False)])
+ availability = 0
+ if quants:
+ for quant in quants:
+ availability += quant.qty
+ product_template.immediately_usable_qty = availability
immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),
- compute='_product_available',
- string='Available to promise',
+ compute='_immediately_usable_qty',
+ string='Available to promise (quant calculation)',
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 "
- "your needs")
+ "your needs , this number is obtained by using the new odoo 8 "
+ "quants, so it gives us the actual curren quants minus reserved"
+ "quants")
diff --git a/stock_available/product_view.xml b/stock_available/product_view.xml
index d05270f75..2b2ee78be 100644
--- a/stock_available/product_view.xml
+++ b/stock_available/product_view.xml
@@ -22,8 +22,8 @@
red:immediately_usable_qty<0;blue:immediately_usable_qty>=0 and state in ('draft', 'end', 'obsolete');black:immediately_usable_qty>=0 and state not in ('draft', 'end', 'obsolete')
-
-
+
+