diff --git a/stock_available/models/product_product.py b/stock_available/models/product_product.py index e76a67ee6..a66f13e2d 100644 --- a/stock_available/models/product_product.py +++ b/stock_available/models/product_product.py @@ -16,7 +16,7 @@ class ProductProduct(models.Model): @api.multi @api.depends('virtual_available') - def _immediately_usable_qty(self): + def _compute_immediately_usable_qty(self): """No-op implementation of the stock available to promise. By default, available to promise = forecasted quantity. @@ -29,11 +29,26 @@ class ProductProduct(models.Model): for prod in self: prod.immediately_usable_qty = prod.virtual_available + @api.multi + @api.depends() + def _compute_potential_qty(self): + """Set potential qty to 0.0 to define the field defintion used by + other modules to inherit it + """ + for product in self: + product.potential_qty = 0.0 + immediately_usable_qty = fields.Float( digits=dp.get_precision('Product Unit of Measure'), - compute='_immediately_usable_qty', + compute='_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") + potential_qty = fields.Float( + compute='_compute_potential_qty', + digits_compute=dp.get_precision('Product Unit of Measure'), + string='Potential', + help="Quantity of this Product that could be produced using " + "the materials already at hand.") diff --git a/stock_available/models/product_template.py b/stock_available/models/product_template.py index 96db9b15f..81e439034 100644 --- a/stock_available/models/product_template.py +++ b/stock_available/models/product_template.py @@ -11,7 +11,7 @@ class ProductTemplate(models.Model): @api.multi @api.depends('product_variant_ids.immediately_usable_qty') - def _immediately_usable_qty(self): + def _compute_immediately_usable_qty(self): """No-op implementation of the stock available to promise. By default, available to promise = forecasted quantity. @@ -24,11 +24,35 @@ class ProductTemplate(models.Model): for tmpl in self: tmpl.immediately_usable_qty = tmpl.virtual_available + @api.multi + @api.depends('product_variant_ids.potential_qty') + def _compute_potential_qty(self): + """Compute the potential as the max of all the variants's potential. + + We can't add the potential of variants: if they share components we + may not be able to make all the variants. + So we set the arbitrary rule that we can promise up to the biggest + variant's potential. + """ + for tmpl in self: + if not tmpl.product_variant_ids: + continue + tmpl.potential_qty = max( + [v.potential_qty for v in tmpl.product_variant_ids]) + immediately_usable_qty = fields.Float( digits=dp.get_precision('Product Unit of Measure'), - compute='_immediately_usable_qty', + compute='_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") + potential_qty = fields.Float( + compute='_compute_potential_qty', + digits_compute=dp.get_precision('Product Unit of Measure'), + string='Potential', + help="Quantity of this Product that could be produced using " + "the materials already at hand. " + "If the product has several variants, this will be the biggest " + "quantity that can be made for a any single variant.") diff --git a/stock_available/views/product_product_view.xml b/stock_available/views/product_product_view.xml index 3c0a2c8bb..03578e61d 100644 --- a/stock_available/views/product_product_view.xml +++ b/stock_available/views/product_product_view.xml @@ -2,8 +2,7 @@ - - + Quantity available to promise (variant tree) product.product @@ -12,7 +11,7 @@ + - - \ No newline at end of file + diff --git a/stock_available/views/product_template_view.xml b/stock_available/views/product_template_view.xml index d24322f18..37c04335c 100644 --- a/stock_available/views/product_template_view.xml +++ b/stock_available/views/product_template_view.xml @@ -2,8 +2,7 @@ - - + Quantity available to promise (form) product.template @@ -12,7 +11,7 @@ + @@ -46,5 +54,4 @@ - - \ No newline at end of file + diff --git a/stock_available/views/res_config_view.xml b/stock_available/views/res_config_view.xml index d9b06a564..615fe9480 100644 --- a/stock_available/views/res_config_view.xml +++ b/stock_available/views/res_config_view.xml @@ -2,8 +2,7 @@ - - + Stock settings: quantity available to promise stock.config.settings @@ -35,5 +34,4 @@ - - \ No newline at end of file + diff --git a/stock_available_immediately/models/product_product.py b/stock_available_immediately/models/product_product.py index 12e973ed8..5122c6176 100644 --- a/stock_available_immediately/models/product_product.py +++ b/stock_available_immediately/models/product_product.py @@ -10,10 +10,10 @@ class ProductProduct(models.Model): @api.multi @api.depends('virtual_available', 'incoming_qty') - def _immediately_usable_qty(self): + def _compute_immediately_usable_qty(self): """Ignore the incoming goods in the quantity available to promise This is the same implementation as for templates.""" - super(ProductProduct, self)._immediately_usable_qty() + super(ProductProduct, self)._compute_immediately_usable_qty() for prod in self: prod.immediately_usable_qty -= prod.incoming_qty diff --git a/stock_available_immediately/models/product_template.py b/stock_available_immediately/models/product_template.py index d8cd5ed34..f2fe4c412 100644 --- a/stock_available_immediately/models/product_template.py +++ b/stock_available_immediately/models/product_template.py @@ -26,10 +26,10 @@ class ProductTemplate(models.Model): @api.multi @api.depends('virtual_available', 'incoming_qty') - def _immediately_usable_qty(self): + def _compute_immediately_usable_qty(self): """Ignore the incoming goods in the quantity available to promise This is the same implementation as for variants.""" - super(ProductTemplate, self)._immediately_usable_qty() + super(ProductTemplate, self)._compute_immediately_usable_qty() for tmpl in self: tmpl.immediately_usable_qty -= tmpl.incoming_qty diff --git a/stock_available_mrp/__openerp__.py b/stock_available_mrp/__openerp__.py index 0aa748b7e..c55d0438e 100644 --- a/stock_available_mrp/__openerp__.py +++ b/stock_available_mrp/__openerp__.py @@ -5,15 +5,13 @@ 'name': 'Consider the production potential is available to promise', 'version': '9.0.1.0.0', "author": u"Numérigraphe," + u"Sodexis," u"Odoo Community Association (OCA)", 'category': 'Hidden', 'depends': [ 'stock_available', 'mrp' ], - 'data': [ - 'views/product_template_view.xml', - ], 'demo': [ 'demo/mrp_bom.yml', ], diff --git a/stock_available_mrp/models/product_product.py b/stock_available_mrp/models/product_product.py index 790ca16a4..f9392622e 100644 --- a/stock_available_mrp/models/product_product.py +++ b/stock_available_mrp/models/product_product.py @@ -5,7 +5,6 @@ from collections import Counter from openerp import models, fields, api -from openerp.addons import decimal_precision as dp from openerp.exceptions import AccessError @@ -13,36 +12,32 @@ from openerp.exceptions import AccessError class ProductProduct(models.Model): _inherit = 'product.product' - potential_qty = fields.Float( - compute='_get_potential_qty', - type='float', - digits_compute=dp.get_precision('Product Unit of Measure'), - string='Potential', - help="Quantity of this Product that could be produced using " - "the materials already at hand.") - # Needed for fields dependencies # When self.potential_qty is compute, we want to force the ORM # to compute all the components potential_qty too. component_ids = fields.Many2many( comodel_name='product.product', - compute='_get_component_ids', + compute='_compute_component_ids', ) @api.multi @api.depends('potential_qty') - def _immediately_usable_qty(self): + def _compute_immediately_usable_qty(self): """Add the potential quantity to the quantity available to promise. This is the same implementation as for templates.""" - super(ProductProduct, self)._immediately_usable_qty() + super(ProductProduct, self)._compute_immediately_usable_qty() for product in self: product.immediately_usable_qty += product.potential_qty @api.multi @api.depends('component_ids.potential_qty') - def _get_potential_qty(self): + def _compute_potential_qty(self): """Compute the potential qty based on the available components.""" + + # call super method available in stock_available + super(ProductProduct, self)._compute_potential_qty() + bom_obj = self.env['mrp.bom'] uom_obj = self.env['product.uom'] @@ -121,7 +116,7 @@ class ProductProduct(models.Model): return needs - def _get_component_ids(self): + def _compute_component_ids(self): """ Compute component_ids by getting all the components for this product. """ diff --git a/stock_available_mrp/models/product_template.py b/stock_available_mrp/models/product_template.py index f87ef6901..49ae2c4b3 100644 --- a/stock_available_mrp/models/product_template.py +++ b/stock_available_mrp/models/product_template.py @@ -2,45 +2,18 @@ # © 2014 Numérigraphe SARL # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api -from openerp.addons import decimal_precision as dp +from openerp import models, api class ProductTemplate(models.Model): _inherit = 'product.template' - potential_qty = fields.Float( - compute='_get_potential_qty', - type='float', - digits_compute=dp.get_precision('Product Unit of Measure'), - string='Potential', - help="Quantity of this Product that could be produced using " - "the materials already at hand. " - "If the product has several variants, this will be the biggest " - "quantity that can be made for a any single variant.") - @api.multi @api.depends('potential_qty') - def _immediately_usable_qty(self): + def _compute_immediately_usable_qty(self): """Add the potential quantity to the quantity available to promise. This is the same implementation as for variants.""" - super(ProductTemplate, self)._immediately_usable_qty() + super(ProductTemplate, self)._compute_immediately_usable_qty() for tmpl in self: tmpl.immediately_usable_qty += tmpl.potential_qty - - @api.multi - @api.depends('product_variant_ids.potential_qty') - def _get_potential_qty(self): - """Compute the potential as the max of all the variants's potential. - - We can't add the potential of variants: if they share components we - may not be able to make all the variants. - So we set the arbitrary rule that we can promise up to the biggest - variant's potential. - """ - for tmpl in self: - if not tmpl.product_variant_ids: - continue - tmpl.potential_qty = max( - [v.potential_qty for v in tmpl.product_variant_ids]) diff --git a/stock_available_mrp/tests/test_potential_qty.py b/stock_available_mrp/tests/test_potential_qty.py index 896655dae..4f9d9fe26 100644 --- a/stock_available_mrp/tests/test_potential_qty.py +++ b/stock_available_mrp/tests/test_potential_qty.py @@ -510,7 +510,7 @@ class TestPotentialQty(TransactionCase): self.assertEqual(5.0, p1.potential_qty) def test_potential_qty__list(self): - # Try to highlight a bug when _get_potential_qty is called on + # Try to highlight a bug when _compute_potential_qty is called on # a recordset with multiple products # Recursive compute is not working diff --git a/stock_available_mrp/views/product_template_view.xml b/stock_available_mrp/views/product_template_view.xml deleted file mode 100644 index 446e0c5c3..000000000 --- a/stock_available_mrp/views/product_template_view.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - Potential quantity on product form - product.template - form - - - - - - - - - - -