From 9ab7f78a7f869b4aec06190ffd2c1a4ab2795e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lionel=20Sausin=20=28Num=C3=A9rigraphe=29?= Date: Fri, 5 Dec 2014 17:25:35 +0100 Subject: [PATCH] [REF] changes suggested by @guewen Set a keyword argument on the context to better respect the convention. Make it clear in docstrings that the side-effects on field_names are intended. Allow the context to contain iterable types supported by the ORM. --- stock_available/product.py | 6 ++++-- stock_available_immediately/product.py | 12 +++++++----- stock_available_mrp/product.py | 4 +++- stock_available_sale/product.py | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/stock_available/product.py b/stock_available/product.py index a4a528eb7..b27993234 100644 --- a/stock_available/product.py +++ b/stock_available/product.py @@ -56,8 +56,10 @@ class ProductProduct(orm.Model): The sub-modules MUST call super()._product_available BEFORE their own computations - Side-effect warning: This method may change the list passed as the - field_names parameter, which will then alter the caller's state.""" + Side-effect warning: By design, we want to change the behavior of the + caller (make it aware that an extra field is being computed). + For this, this method MAY change the list passed as the parameter + `field_names`.""" # If we didn't get a field_names list, there's nothing to do if field_names is None: return super(ProductProduct, self)._product_available( diff --git a/stock_available_immediately/product.py b/stock_available_immediately/product.py index 7c133523e..66d98ca3c 100644 --- a/stock_available_immediately/product.py +++ b/stock_available_immediately/product.py @@ -26,15 +26,17 @@ class product_immediately_usable(orm.Model): """Subtract incoming qty from immediately_usable_qty We don't need to override the function fields, the module stock_available - takes of it for us. - - Side-effect warning: This method may change the list passed as the - field_names parameter, which will then alter the caller's state.""" + takes care of it for us.""" _inherit = 'product.product' def _product_available(self, cr, uid, ids, field_names=None, arg=False, context=None): - """Ignore the incoming goods in the quantity available to promise""" + """Ignore the incoming goods in the quantity available to promise + + Side-effect warning: By design, we want to change the behavior of the + caller (make it aware that an extra field is being computed). + For this, this method MAY change the list passed as the parameter + `field_names`.""" # If we didn't get a field_names list, there's nothing to do if field_names is None or 'immediately_usable_qty' not in field_names: return super(product_immediately_usable, self)._product_available( diff --git a/stock_available_mrp/product.py b/stock_available_mrp/product.py index 4d5cd2f6f..f36b86a5c 100644 --- a/stock_available_mrp/product.py +++ b/stock_available_mrp/product.py @@ -73,10 +73,12 @@ class product_product(orm.Model): return res def _compute_potential_qty_from_bom(self, cr, uid, bom_id, to_uom, - context): + context=None): """Compute the potential qty from BoMs with components available""" bom_obj = self.pool['mrp.bom'] uom_obj = self.pool['product.uom'] + if context is None: + context = {} if 'uom' in context: context_wo_uom = context.copy() del context_wo_uom['uom'] diff --git a/stock_available_sale/product.py b/stock_available_sale/product.py index 512c41eac..ada61ed22 100644 --- a/stock_available_sale/product.py +++ b/stock_available_sale/product.py @@ -134,7 +134,7 @@ class ProductProduct(orm.Model): # location if context.get('location', False): # Either a single or multiple locations can be in the context - if not isinstance(context['location'], list): + if isinstance(context['location'], (int, long)): location_ids = [context['location']] else: location_ids = context['location']