mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
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:
committed by
Florian da Costa
parent
3cdb01ba16
commit
335dc6de1d
@@ -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'),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user