Domain with function field

52 views
Skip to first unread message

Maxime Richez

unread,
Jan 22, 2018, 3:55:00 AM1/22/18
to tryton
Hi,

In domain definition, operand cannot be a field. So, i'm wondering how doing this kind of view: for example, a listing of all products having a cost_price greater than list price.
I would define this domain ['cost_price', '>', Eval('list_price')] but this is not working.
Another idea, was to define a function field on a boolean field (flag) and the setter of this function field will return true or false about the comparison between 'cost_price' and 'list_price'... and then creating a treeview with domain ['flag', '=' ,'True'] but once again, how to define a correct domain in the searcher function of the flag function field ?
Thanks for ideas, help...

Cédric Krier

unread,
Jan 23, 2018, 4:10:07 AM1/23/18
to tryton
For now, I think the Function field is the only option. The searcher
should probably have to return a clause like [('id', 'in', query)].
This is not optimal but it should work.

This is issue came up from time to time. I think it could be addresses
by extending the domain syntax. We will need to have a way to put a
column (with the option of being nested) as value. For example we could
have an object Field:

[('cost_price', '>', Field('list_price'))]

I think on the client we could have this syntax:

"Cost Price": > @"List Price"


--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Maxime Richez

unread,
Jan 23, 2018, 8:50:03 AM1/23/18
to tryton
> For now, I think the Function field is the only option. The searcher
> should probably have to return a clause like [('id', 'in', query)].
> This is not optimal but it should work.

2 questions:

- In the case of the function field is only used in a treeview for filtering data (just for display), isn't better to define a new modelview based on a query (for example: https://bitbucket.org/zikzakmedia/trytond-product_quantity_by_location/src ) Would it be more optimal ?

- What about the search function if one of the field to compare with another field is already a function field (for example product quantity field)? Is the only way of doing the search is still the query (that would be very complex in the case of quantity field,no ?) ?

> This is issue came up from time to time. I think it could be addresses
> by extending the domain syntax. We will need to have a way to put a
> column (with the option of being nested) as value. For example we could
> have an object Field:
>
> [('cost_price', '>', Field('list_price'))]
>
> I think on the client we could have this syntax:
>
> "Cost Price": > @"List Price"
>

Would be nice :-)

Cédric Krier

unread,
Jan 23, 2018, 9:25:08 AM1/23/18
to tryton
On 2018-01-23 05:50, Maxime Richez wrote:
> > For now, I think the Function field is the only option. The searcher
> > should probably have to return a clause like [('id', 'in', query)].
> > This is not optimal but it should work.
>
> 2 questions:
>
> - In the case of the function field is only used in a treeview for
> filtering data (just for display), isn't better to define a new
> modelview based on a query (for example:
> https://bitbucket.org/zikzakmedia/trytond-product_quantity_by_location/src
> ) Would it be more optimal ?

A new model means new views, new access rights etc. Also module that
extend the base may need to be aware of this new model.

> - What about the search function if one of the field to compare with
> another field is already a function field (for example product
> quantity field)? Is the only way of doing the search is still the
> query (that would be very complex in the case of quantity field,no ?)
> ?

Of course you can construct the domain by evaluating the records in
Python. But it will work only if you evaluate a small list of records.
Larger one will require to write a complex SQL query.
Reply all
Reply to author
Forward
0 new messages