From 8c6a72e29d0fceceafd8c0de54f7b5cf414ff858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon?= Date: Mon, 3 Sep 2018 16:05:00 +0200 Subject: [PATCH] [10.0][CHG]stock_available...: improve stock methods computation --- stock_available/models/product_product.py | 13 ++++++++++--- stock_available/models/product_template.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/stock_available/models/product_product.py b/stock_available/models/product_product.py index 8b446b0be..af76f6139 100644 --- a/stock_available/models/product_product.py +++ b/stock_available/models/product_product.py @@ -26,18 +26,25 @@ class ProductProduct(models.Model): @api.multi def _compute_available_quantities_dict(self): + stock_dict = self._compute_quantities_dict( + self._context.get('lot_id'), + self._context.get('owner_id'), + self._context.get('package_id'), + self._context.get('from_date'), + self._context.get('to_date')) res = {} for product in self: res[product.id] = { - 'immediately_usable_qty': product.virtual_available, + 'immediately_usable_qty': stock_dict[product.id][ + 'virtual_available'], 'potential_qty': 0.0 } - return res + return res, stock_dict @api.multi @api.depends('virtual_available') def _compute_available_quantities(self): - res = self._compute_available_quantities_dict() + res, _ = self._compute_available_quantities_dict() for product in self: for key, value in res[product.id].items(): if hasattr(product, key): diff --git a/stock_available/models/product_template.py b/stock_available/models/product_template.py index 071a96136..e02336950 100644 --- a/stock_available/models/product_template.py +++ b/stock_available/models/product_template.py @@ -31,7 +31,7 @@ class ProductTemplate(models.Model): @api.multi def _compute_available_quantities_dict(self): - variants_dict = self.mapped( + variants_dict, _ = self.mapped( 'product_variant_ids')._compute_available_quantities_dict() res = {} for template in self: