Order application of domain clause

22 views
Skip to first unread message

Thierry Bruyere

unread,
Oct 27, 2017, 9:50:06 AM10/27/17
to tryton-dev
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?

Cédric Krier

unread,
Oct 27, 2017, 7:25:06 PM10/27/17
to tryton-dev
On 2017-10-27 06:35, Thierry Bruyere wrote:
> 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?

No, each clause is evaluated one by one individually. What may happen is
when the clause evaluation result is a SQL query then the database may
perform optimization by using a specific query plan.

If this is really a performance killer, you may create a custom function
field which implement a searcher that compose many clause together. In
your case, it will reproduce the _search_quantity but on the desired
subset of products.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages