From c23889e8ba64925ded9fd311017c23254145f85a Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Fri, 4 Mar 2016 11:03:16 +0100 Subject: [PATCH] stock_available / stock_available_mrp : add possibility to choose which field use to compute potential --- stock_available_mrp/README.rst | 3 +++ stock_available_mrp/__openerp__.py | 2 +- stock_available_mrp/models/product_product.py | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/stock_available_mrp/README.rst b/stock_available_mrp/README.rst index d32c27ae8..b47d8dbf0 100644 --- a/stock_available_mrp/README.rst +++ b/stock_available_mrp/README.rst @@ -9,6 +9,9 @@ Consider the production potential is available to promise This module takes the potential quantities available for Products into account in the quantity available to promise, where the "Potential quantity" is the quantity that can be manufactured with the components immediately at hand. +By configuration, the "Potential quantity" can be computed based on other product field. +For example, "Potential quantity" can be the quantity that can be manufactured +with the components available to promise. Usage ===== diff --git a/stock_available_mrp/__openerp__.py b/stock_available_mrp/__openerp__.py index 0e10d6a6e..64ad57aaa 100644 --- a/stock_available_mrp/__openerp__.py +++ b/stock_available_mrp/__openerp__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Consider the production potential is available to promise', - 'version': '8.0.3.0.1', + 'version': '8.0.3.1.0', "author": u"Numérigraphe," u"Odoo Community Association (OCA)", 'category': 'Hidden', diff --git a/stock_available_mrp/models/product_product.py b/stock_available_mrp/models/product_product.py index b9ade817e..91daaab75 100644 --- a/stock_available_mrp/models/product_product.py +++ b/stock_available_mrp/models/product_product.py @@ -6,6 +6,7 @@ from collections import Counter from openerp import models, fields, api from openerp.addons import decimal_precision as dp +from openerp.tools.safe_eval import safe_eval class ProductProduct(models.Model): @@ -35,6 +36,12 @@ class ProductProduct(models.Model): bom_obj = self.env['mrp.bom'] uom_obj = self.env['product.uom'] + icp = self.env['ir.config_parameter'] + stock_available_mrp_based_on = safe_eval( + icp.get_param('stock_available_mrp_based_on', 'False')) + if not stock_available_mrp_based_on: + stock_available_mrp_based_on = 'qty_available' + for product in self: bom_id = bom_obj._bom_find(product_id=product.id) if not bom_id: @@ -53,7 +60,7 @@ class ProductProduct(models.Model): else: # Find the lowest quantity we can make with the stock at hand components_potential_qty = min( - [component.qty_available // need + [getattr(component, stock_available_mrp_based_on) // need for component, need in component_needs.items()] )