mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[14.0] stock_available: improve search performance
This commit is contained in:
committed by
Jasmin Solanki
parent
7942ba4fa5
commit
c59d76eba4
@@ -67,6 +67,9 @@ class ProductProduct(models.Model):
|
||||
"the materials already at hand.",
|
||||
)
|
||||
|
||||
def _get_search_immediately_usable_qty_domain(self):
|
||||
return [("type", "=", "product")]
|
||||
|
||||
@api.model
|
||||
def _search_immediately_usable_qty(self, operator, value):
|
||||
"""Search function for the immediately_usable_qty field.
|
||||
@@ -76,9 +79,10 @@ class ProductProduct(models.Model):
|
||||
:param value: str
|
||||
:return: list of tuple (domain)
|
||||
"""
|
||||
products = self.search([])
|
||||
# Force prefetch
|
||||
products.mapped("immediately_usable_qty")
|
||||
product_domain = self._get_search_immediately_usable_qty_domain()
|
||||
products = self.with_context(prefetch_fields=False).search(
|
||||
product_domain, order="id"
|
||||
)
|
||||
product_ids = []
|
||||
for product in products:
|
||||
if OPERATORS[operator](product.immediately_usable_qty, value):
|
||||
|
||||
Reference in New Issue
Block a user