From beddc649412c38b558d5f774ad0f451b8bcaf204 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 5 Apr 2022 14:54:53 +0200 Subject: [PATCH] [FIX] stock_available_mrp: normal BoM available to promise Normal BoM products (those which are manufactured) are regular stored products and their immediately_usable_qty will be summed with potential stock. This was the expected behavior of the module and it was lost at some point. Phantom BoM products (kits) don't have real stock so their available to promise quantity will be the same as the potential. As an improvement, we've added the possibility to override the sum of potential and available to promise. In some cases such addition doesn't make sense as we don't know how long can take to manufacture those potential units. TT35589 --- stock_available_mrp/README.rst | 15 +++++- stock_available_mrp/__manifest__.py | 1 + stock_available_mrp/models/__init__.py | 2 +- stock_available_mrp/models/mrp_bom.py | 13 +++++ stock_available_mrp/models/product_product.py | 15 +++++- stock_available_mrp/readme/CONTRIBUTORS.rst | 1 + stock_available_mrp/readme/ROADMAP.rst | 4 +- stock_available_mrp/readme/USAGE.rst | 6 +++ .../static/description/index.html | 54 +++++++++++-------- .../tests/test_potential_qty.py | 20 ++++++- stock_available_mrp/views/mrp_bom_views.xml | 15 ++++++ 11 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 stock_available_mrp/models/mrp_bom.py create mode 100644 stock_available_mrp/readme/USAGE.rst create mode 100644 stock_available_mrp/views/mrp_bom_views.xml diff --git a/stock_available_mrp/README.rst b/stock_available_mrp/README.rst index f6b7538ea..3e6be77f6 100644 --- a/stock_available_mrp/README.rst +++ b/stock_available_mrp/README.rst @@ -37,14 +37,24 @@ with the components available to promise. .. contents:: :local: +Usage +===== + +It's possible to avoid adding potential stock to available to promise stock at Bill of +Materials level. This is interesting in case that sum is missleading due to uncertain +manufacturing processes. To do so: + +- Go to that specific Bill of Materials and in the Miscellaneous tab set the option + **Avoid adding potential to available to promise** on. + Known issues / Roadmap ====================== Known issues ~~~~~~~~~~~~ -The manufacturing delays are not taken into account : this module assumes that +The manufacturing delays are not taken into account: this module assumes that if you have components in stock goods, you can manufacture finished goods -quickly enough. +quickly enough. This can be overriden at BoM level though. As a consequence, and to avoid overestimating, **only the first level** of Bill of Materials is considered. @@ -113,6 +123,7 @@ Contributors * `Tecnativa `_: * Víctor Martínez + * David Vidal Maintainers ~~~~~~~~~~~ diff --git a/stock_available_mrp/__manifest__.py b/stock_available_mrp/__manifest__.py index 16643cddd..b5ec28a13 100644 --- a/stock_available_mrp/__manifest__.py +++ b/stock_available_mrp/__manifest__.py @@ -7,6 +7,7 @@ "website": "https://github.com/OCA/stock-logistics-warehouse", "category": "Hidden", "depends": ["stock_available", "mrp"], + "data": ["views/mrp_bom_views.xml"], "demo": ["demo/mrp_data.xml"], "license": "AGPL-3", "installable": True, diff --git a/stock_available_mrp/models/__init__.py b/stock_available_mrp/models/__init__.py index bf91af2eb..4612d56ea 100644 --- a/stock_available_mrp/models/__init__.py +++ b/stock_available_mrp/models/__init__.py @@ -1,4 +1,4 @@ # Copyright 2014 Numérigraphe SARL # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - +from . import mrp_bom from . import product_product diff --git a/stock_available_mrp/models/mrp_bom.py b/stock_available_mrp/models/mrp_bom.py new file mode 100644 index 000000000..619e1b1df --- /dev/null +++ b/stock_available_mrp/models/mrp_bom.py @@ -0,0 +1,13 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class MrpBom(models.Model): + _inherit = "mrp.bom" + + add_potential_exception = fields.Boolean( + string="Avoid adding potential to available to promise", + help="If potential qty added to available to promise is set in the company " + "we can override this option for single BoMs", + ) diff --git a/stock_available_mrp/models/product_product.py b/stock_available_mrp/models/product_product.py index 569a75c1a..0eb2b25a3 100644 --- a/stock_available_mrp/models/product_product.py +++ b/stock_available_mrp/models/product_product.py @@ -109,8 +109,19 @@ class ProductProduct(models.Model): ) res[product.id]["potential_qty"] = potential_qty - res[product.id]["immediately_usable_qty"] = potential_qty - + # Normal BoM products (those which are manufactured) are regular stored + # products and their immediately_usable_qty will be the sum of its regular + # available to promise quanity as storable product and its potential qty + # Phantom BoM products (kits) don't have real stock so their available + # to promise quantity will be the same as the potential. + if bom_id.type == "phantom": + res[product.id]["immediately_usable_qty"] = potential_qty + # We can override at BoM level to add the potential quantity to the + # manufactured product. This could be the case when the manufacturing + # proccess is uncertain and the promising such quantities could be + # missleading. + elif not bom_id.add_potential_exception: + res[product.id]["immediately_usable_qty"] += potential_qty return res, stock_dict def _explode_boms(self): diff --git a/stock_available_mrp/readme/CONTRIBUTORS.rst b/stock_available_mrp/readme/CONTRIBUTORS.rst index 1089a647b..50df76d7c 100644 --- a/stock_available_mrp/readme/CONTRIBUTORS.rst +++ b/stock_available_mrp/readme/CONTRIBUTORS.rst @@ -8,3 +8,4 @@ * `Tecnativa `_: * Víctor Martínez + * David Vidal diff --git a/stock_available_mrp/readme/ROADMAP.rst b/stock_available_mrp/readme/ROADMAP.rst index 88ebb1f2e..5d0b89e84 100644 --- a/stock_available_mrp/readme/ROADMAP.rst +++ b/stock_available_mrp/readme/ROADMAP.rst @@ -1,8 +1,8 @@ Known issues ~~~~~~~~~~~~ -The manufacturing delays are not taken into account : this module assumes that +The manufacturing delays are not taken into account: this module assumes that if you have components in stock goods, you can manufacture finished goods -quickly enough. +quickly enough. This can be overriden at BoM level though. As a consequence, and to avoid overestimating, **only the first level** of Bill of Materials is considered. diff --git a/stock_available_mrp/readme/USAGE.rst b/stock_available_mrp/readme/USAGE.rst new file mode 100644 index 000000000..841a63eb1 --- /dev/null +++ b/stock_available_mrp/readme/USAGE.rst @@ -0,0 +1,6 @@ +It's possible to avoid adding potential stock to available to promise stock at Bill of +Materials level. This is interesting in case that sum is missleading due to uncertain +manufacturing processes. To do so: + +- Go to that specific Bill of Materials and in the Miscellaneous tab set the option + **Avoid adding potential to available to promise** on. diff --git a/stock_available_mrp/static/description/index.html b/stock_available_mrp/static/description/index.html index df95846e2..2c9c56cce 100644 --- a/stock_available_mrp/static/description/index.html +++ b/stock_available_mrp/static/description/index.html @@ -3,7 +3,7 @@ - + Consider the production potential is available to promise