diff --git a/stock_available_unreserved/models/product.py b/stock_available_unreserved/models/product.py index ff22b2b80..87c039934 100644 --- a/stock_available_unreserved/models/product.py +++ b/stock_available_unreserved/models/product.py @@ -23,37 +23,15 @@ class ProductTemplate(models.Model): string='Unreserved stock quantity') @api.multi + @api.depends('product_variant_ids.qty_available_not_res') def _compute_product_available_not_res(self): no_new = self.filtered( lambda x: not isinstance(x.id, models.NewId)) - res = no_new._product_available() for tmpl in no_new: - qty = res[tmpl.id]['qty_available_not_res'] - tmpl.qty_available_not_res = qty - text = res[tmpl.id]['qty_available_stock_text'] - tmpl.qty_available_stock_text = text - - def _compute_quantities_dict(self): - prod_available = super(ProductTemplate, self).\ - _compute_quantities_dict() - - variants = self.mapped('product_variant_ids') - variant_available = variants._product_available() - - for product in self: - if isinstance(product.id, models.NewId): - continue - qty_available_not_res = 0.0 - text = '' - for p in product.product_variant_ids: - qty = variant_available[p.id]["qty_available_not_res"] - qty_available_not_res += qty - text = variant_available[p.id]["qty_available_stock_text"] - prod_available[product.id].update({ - "qty_available_not_res": qty_available_not_res, - "qty_available_stock_text": text, - }) - return prod_available + tmpl.qty_available_not_res = sum(tmpl.mapped( + 'product_variant_ids.qty_available_not_res')) + tmpl.qty_available_stock_text = "/".join(tmpl.mapped( + 'product_variant_ids.qty_available_stock_text')) @api.multi def action_open_quants_unreserved(self): @@ -79,7 +57,7 @@ class ProductProduct(models.Model): @api.multi def _compute_qty_available_not_res(self): - res = self._product_available() + res = self._compute_product_available_not_res_dict() for prod in self: qty = res[prod.id]['qty_available_not_res'] text = res[prod.id]['qty_available_stock_text'] @@ -106,12 +84,9 @@ class ProductProduct(models.Model): return False @api.multi - def _compute_quantities_dict(self, lot_id, owner_id, package_id, - from_date=False, to_date=False): - res = super(ProductProduct, self).\ - _compute_quantities_dict( - lot_id=lot_id, owner_id=owner_id, package_id=package_id, - from_date=from_date, to_date=to_date) + def _compute_product_available_not_res_dict(self): + + res = {} domain_quant = self._prepare_domain_available_not_res(self) @@ -126,6 +101,7 @@ class ProductProduct(models.Model): values_prod.setdefault(quant['product_id'][0], 0) values_prod[quant['product_id'][0]] += quant['qty'] for product in self: + res[product.id] = {} # get total qty for the product qty = float_round(values_prod.get(product.id, 0.0), precision_rounding=product.uom_id.rounding)