diff --git a/stock_available_mrp/README.rst b/__unported__/stock_available_mrp/README.rst similarity index 100% rename from stock_available_mrp/README.rst rename to __unported__/stock_available_mrp/README.rst diff --git a/stock_available_sale/README.rst b/__unported__/stock_available_sale/README.rst similarity index 100% rename from stock_available_sale/README.rst rename to __unported__/stock_available_sale/README.rst diff --git a/stock_available/product.py b/stock_available/product.py index 1a3b72a59fef..620bfb824c6c 100644 --- a/stock_available/product.py +++ b/stock_available/product.py @@ -22,16 +22,16 @@ from openerp.addons import decimal_precision as dp -class ProductTemplate(models.Model): +class Product(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' + _inherit = 'product.product' @api.depends('virtual_available') - def _product_available(self): + def _immediately_usable_qty(self): """No-op implementation of the stock available to promise. By default, available to promise = forecasted quantity. @@ -43,7 +43,41 @@ def _product_available(self): immediately_usable_qty = fields.Float( digits=dp.get_precision('Product Unit of Measure'), - compute='_product_available', + compute='_immediately_usable_qty', + 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 " + "your needs") + + +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' + + @api.depends('virtual_available') + def _immediately_usable_qty(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.""" + product_model = self.env['product.product'] + for product_template in self: + products = product_model.search([( + 'product_tmpl_id', '=', product_template.id)]) + qty = 0 + for product in products: + qty += product.immediately_usable_qty + product_template.immediately_usable_qty = qty + + immediately_usable_qty = fields.Float( + digits=dp.get_precision('Product Unit of Measure'), + compute='_immediately_usable_qty', string='Available to promise', help="Stock for this Product that can be safely proposed " "for sale to Customers.\n" diff --git a/stock_available_immediately/product.py b/stock_available_immediately/product.py index 05d8ad2e7f1d..491e44d1d19b 100644 --- a/stock_available_immediately/product.py +++ b/stock_available_immediately/product.py @@ -19,18 +19,15 @@ # ############################################################################## -from openerp import models, fields, api +from openerp import models -class ProductTemplate(models.Model): +class Product(models.Model): """Subtract incoming qty from immediately_usable_qty""" - _inherit = 'product.template' + _inherit = 'product.product' - @api.depends('virtual_available') - def _product_available(self): + def _immediately_usable_qty(self): """Ignore the incoming goods in the quantity available to promise""" - super(ProductTemplate, self)._product_available() + super(Product, self)._immediately_usable_qty() for product in self: product.immediately_usable_qty -= product.incoming_qty - - immediately_usable_qty = fields.Float(compute='_product_available')