diff --git a/stock_available/README.rst b/stock_available/README.rst index 01663154a..d996ef92f 100644 --- a/stock_available/README.rst +++ b/stock_available/README.rst @@ -1,3 +1,8 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========================== Stock available to promise ========================== @@ -8,16 +13,16 @@ configuration, it can account for various data such as sales quotations or immediate production capacity. In case of immediate production capacity, it is possible to configure on which field the potential is computed, by default Quantity On Hand is used. -This can be configured in the menu Settings > Configuration > Warehouse. +This can be configured in `Inventory` > `Configuration` > `Settings`. Configuration ============= By default, this module computes the stock available to promise as the virtual stock. -To take davantage of the additional features, you must which information you +To take advantage of the additional features, you must which information you want to base the computation, by checking one or more boxes in the settings: -`Configuration` > `Warehouse` > `Stock available to promise`. +`Inventory` > `Configuration` > `Settings` > `Stock available to promise`. In case of "Include the production potential", it is also possible to configure which field of product to use to compute the production potential. @@ -28,25 +33,43 @@ This module adds a field named `Available for sale` on the Product form. Various additional fields may be added, depending on which information you chose to base the computation on. +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/153/10.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + Credits ======= +Images +------ + +* Odoo Community Association: `Icon `_. + Contributors ------------ * Lionel Sausin (Numérigraphe) * Sodexis -* many others contributed to sub-modules, please refer to each sub-module's credits Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. -OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. \ No newline at end of file diff --git a/stock_available/__init__.py b/stock_available/__init__.py index 4016a3092..1c7afe72c 100644 --- a/stock_available/__init__.py +++ b/stock_available/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# © 2014 Numérigraphe, Sodexis +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/stock_available/__openerp__.py b/stock_available/__manifest__.py similarity index 84% rename from stock_available/__openerp__.py rename to stock_available/__manifest__.py index 59319331b..aa40dd404 100644 --- a/stock_available/__openerp__.py +++ b/stock_available/__manifest__.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -# © 2014 Numérigraphe, Sodexis +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Stock available to promise', - 'version': '9.0.1.1.0', + 'version': '10.0.1.0.0', "author": "Numérigraphe, Sodexis, Odoo Community Association (OCA)", 'category': 'Warehouse', 'depends': ['stock'], diff --git a/stock_available/models/__init__.py b/stock_available/models/__init__.py index c74571e26..ee9f0d3ba 100644 --- a/stock_available/models/__init__.py +++ b/stock_available/models/__init__.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- -# © 2014 Numérigraphe, Sodexis +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import product_template, product_product, res_config +from . import product_template +from . import product_product +from . import res_config diff --git a/stock_available/models/product_product.py b/stock_available/models/product_product.py index e76a67ee6..d908c2ea4 100644 --- a/stock_available/models/product_product.py +++ b/stock_available/models/product_product.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -# © 2014 Numérigraphe, Sodexis +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis # 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 odoo import models, fields, api +from odoo.addons import decimal_precision as dp class ProductProduct(models.Model): @@ -16,7 +17,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 +30,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=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..dc032f0d3 100644 --- a/stock_available/models/product_template.py +++ b/stock_available/models/product_template.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -# © 2014 Numérigraphe, Sodexis +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis # 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 odoo import models, fields, api +from odoo.addons import decimal_precision as dp class ProductTemplate(models.Model): @@ -11,7 +12,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 +25,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=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/models/res_config.py b/stock_available/models/res_config.py index 968c49285..aec970a73 100644 --- a/stock_available/models/res_config.py +++ b/stock_available/models/res_config.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -# © 2014 Numérigraphe, Sodexis +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, models, fields +from odoo import api, models, fields class StockConfig(models.TransientModel): diff --git a/stock_available/static/description/icon.png b/stock_available/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_available/static/description/icon.png differ diff --git a/stock_available/tests/__init__.py b/stock_available/tests/__init__.py new file mode 100644 index 000000000..2e7403795 --- /dev/null +++ b/stock_available/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_stock_available diff --git a/stock_available/tests/test_stock_available.py b/stock_available/tests/test_stock_available.py new file mode 100644 index 000000000..1c9dd0626 --- /dev/null +++ b/stock_available/tests/test_stock_available.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 Numérigraphe +# Copyright 2016 Sodexis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestStockLogisticsWarehouse(TransactionCase): + + def test_res_config(self): + """Test the config file""" + stock_setting = self.env['stock.config.settings'].create({}) + + self.assertEquals( + stock_setting.stock_available_mrp_based_on, + 'qty_available') + stock_setting.stock_available_mrp_based_on = 'immediately_usable_qty' + stock_setting.set_stock_available_mrp_based_on() + self.assertEquals( + stock_setting.stock_available_mrp_based_on, + 'immediately_usable_qty') diff --git a/stock_available/views/product_product_view.xml b/stock_available/views/product_product_view.xml index 3c0a2c8bb..3f21973c7 100644 --- a/stock_available/views/product_product_view.xml +++ b/stock_available/views/product_product_view.xml @@ -1,9 +1,9 @@ - - - + Quantity available to promise (variant tree) product.product @@ -12,7 +12,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..e5705d63f 100644 --- a/stock_available/views/product_template_view.xml +++ b/stock_available/views/product_template_view.xml @@ -1,9 +1,9 @@ - - - + Quantity available to promise (form) product.template @@ -12,7 +12,7 @@ + @@ -29,7 +38,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') + virtual_available<0 or immediately_usable_qty<0 + virtual_available>=0 or immediately_usable_qty>0 @@ -46,5 +56,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..95b68e371 100644 --- a/stock_available/views/res_config_view.xml +++ b/stock_available/views/res_config_view.xml @@ -1,9 +1,9 @@ - - - + Stock settings: quantity available to promise stock.config.settings @@ -35,5 +35,4 @@ - - \ No newline at end of file +