Help on Pyson Statement

62 views
Skip to first unread message

Maxime Richez

unread,
Nov 24, 2017, 5:15:15 AM11/24/17
to tryton-dev
Hi,

We are looking to define a specific rule on a button (Models-> Models Access -> Buttons). Rule would be : 2 users needs to validate button if amount is greater than a specific value.
We try this expression : [["total_amount", ">", 500]]
This is not working. What should be the correct expression ?
Thanks !

Sergi Almacellas Abellana

unread,
Nov 24, 2017, 5:21:19 AM11/24/17
to tryto...@googlegroups.com
El 24/11/17 a les 11:15, Maxime Richez ha escrit:
> Hi,
>
> We are looking to define a specific rule on a button (Models-> Models Access -> Buttons). Rule would be : 2 users needs to validate button if amount is greater than a specific value.
> We try this expression : [["total_amount", ">", 500]] > This is not working. What should be the correct expression ?
You have some examples in the test suite:

http://hg.tryton.org/trytond/file/34073513c887/trytond/tests/test_modelview.py#l194

Have you tried?:

Eval('self', {}).get('total_amount', 0) > 500

Hope it helps.


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Maxime Richez

unread,
Nov 24, 2017, 6:02:52 AM11/24/17
to tryton-dev
> You have some examples in the test suite:
>
> http://hg.tryton.org/trytond/file/34073513c887/trytond/tests/test_modelview.py#l194
>
> Have you tried?:
>
> Eval('self', {}).get('total_amount', 0) > 500
>
> Hope it helps.

Thanks but we are testing from the tryton client, and expression is not a valid Pyson expression. Is there a way to convert your expression in the gui client ?
We convert your expression with PYTHONEncoder and then we introduce the result in the GUI, and it's working whith this value:
{"s2": 500, "s1": {"d": 0, "k": "total_amount", "__class__": "Get", "v": {"d": {}, "__class__": "Eval", "v": "self"}}, "e": false, "__class__": "Greater"}

Is there a tool in the gui to convert expression to Pyson ?


Sergi Almacellas Abellana

unread,
Nov 24, 2017, 6:09:50 AM11/24/17
to tryto...@googlegroups.com
El 24/11/17 a les 12:02, Maxime Richez ha escrit:
Indeed there is a widget to manipulate the pyson statements on the
tryton client [1]. You should be able to enter the pyson expresion on
client and it will automatically encode the values when sending to the
server.

But I see the widget is not activated for this field.

I will create an issue in order to fix it.

Thanks,

[1] https://bugs.tryton.org/issue4631

Sergi Almacellas Abellana

unread,
Nov 24, 2017, 6:12:55 AM11/24/17
to tryto...@googlegroups.com
El 24/11/17 a les 12:09, Sergi Almacellas Abellana ha escrit:
>
> I will create an issue in order to fix it.
Done: https://bugs.tryton.org/issue6964

It will be great if you can test it :)

Cédric Krier

unread,
Nov 24, 2017, 6:20:05 AM11/24/17
to tryton-dev
On 2017-11-24 03:02, Maxime Richez wrote:
> Is there a tool in the gui to convert expression to Pyson ?

We have the pyson widget now. I think the condition field is missing it.

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

Maxime Richez

unread,
Nov 24, 2017, 7:00:37 AM11/24/17
to tryton-dev

> > I will create an issue in order to fix it.
> Done: https://bugs.tryton.org/issue6964
>
> It will be great if you can test it :)
>

Ok; tested ! Easier with the widget :-)

Reply all
Reply to author
Forward
0 new messages