We wanted to make a list of our products with zero stock for a specific process in our job.
For this purpose we have defined a context to include all the "locations" of type "storage".
Then we launch a search on the model product with a domain.
Example:
class Product:
__metaclass__ = PoolMeta
__name__ = 'product.product'
...
@classmethod
def check_qty(cls):
pool = Pool()
Date = pool.get('ir.date')
Stock = pool.get('stock.location')
locations = Stock.search([('type', '=', 'storage')])
stock_date_end = Date.today()
domain = [
('type', '=', 'goods'),
('quantity', '=', 0.0),
]
with Transaction().set_context(locations=[
l.id for l in locations],
stock_date_end=stock_date_end):
products = cls.search(domain)
...
With this method, we found that the system first calculates the quantity for all products without
using our first domain clause which limits the number of items to be processed.
To simplify the example we have defined a search on' Goods' type products
but in our case we work with other parameters.
Is it possible to apply this type of search by domain by forcing the order of domain clauses
and so limiting the number of items involved in quantity calculation?