From 6c1691349338330e0f5441b4e688d3de803fe9bf Mon Sep 17 00:00:00 2001 From: gfcapalbo Date: Wed, 18 Mar 2015 13:20:03 +0100 Subject: [PATCH] [FIX] corrected calculation of immediately_usable_qty on product.product and product.template, now takes in account variants and correctly displays value. [FLAKE8] Removing duplicate modules and moving README.rst into __unported__ --- .../stock_available_mrp}/README.rst | 0 .../stock_available_sale}/README.rst | 0 stock_available/product.py | 42 +++++++++++++++++-- stock_available_immediately/product.py | 13 +++--- 4 files changed, 43 insertions(+), 12 deletions(-) rename {stock_available_mrp => __unported__/stock_available_mrp}/README.rst (100%) rename {stock_available_sale => __unported__/stock_available_sale}/README.rst (100%) 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 1a3b72a59..620bfb824 100644 --- a/stock_available/product.py +++ b/stock_available/product.py @@ -22,16 +22,16 @@ from openerp import models, fields, api 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 @@ class ProductTemplate(models.Model): 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 05d8ad2e7..491e44d1d 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')