product_available improvements

* fix the dependencies for the computed field

* use api.multi instead of api.one to avoid calling
  super()._immediately_usable_qty in a loop (this improves perfs on a tree view
  display)
This commit is contained in:
Alexandre Fayolle
2015-10-26 13:56:24 +01:00
committed by Florian da Costa
parent 3cdb01ba16
commit 335dc6de1d
2 changed files with 10 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ class ProductProduct(models.Model):
"""
_inherit = 'product.product'
@api.one
@api.multi
@api.depends('virtual_available')
def _immediately_usable_qty(self):
"""No-op implementation of the stock available to promise.
@@ -23,7 +23,8 @@ class ProductProduct(models.Model):
Must be overridden by another module that actually implement
computations."""
self.immediately_usable_qty = self.virtual_available
for prod in self:
prod.immediately_usable_qty = prod.virtual_available
immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),

View File

@@ -9,12 +9,15 @@ from openerp.addons import decimal_precision as dp
class ProductTemplate(models.Model):
_inherit = 'product.template'
@api.one
@api.depends('virtual_available')
@api.multi
@api.depends('product_variant_ids.immediately_usable_qty')
def _immediately_usable_qty(self):
"""Compute the quantity using all the variants"""
self.immediately_usable_qty = sum(
[v.immediately_usable_qty for v in self.product_variant_ids])
for tmpl in self:
tmpl.immediately_usable_qty = sum(
v.immediately_usable_qty
for v in tmpl.product_variant_ids
)
immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),