Re: [tryton-dev] Order application of domain clause

2017-10-27 Thread Cédric Krier
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.kr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20171027232037.GB6037%40kei.


[tryton-dev] Order application of domain clause

2017-10-27 Thread Thierry Bruyere
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?

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/bc8d9db3-d0cb-4883-871f-4f961116188f%40googlegroups.com.