# PYSON statements in Tryton 5.x

**URL:** https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387
**Category:** Developer
**Created:** [February 28, 2020, 1:55pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387 "2020-02-28T13:55:56Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [February 28, 2020, 1:55pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/1 "2020-02-28T13:55:56Z")

</div>

We use the following PYSON statements in `states` attribute:

```
Eval('_user') != Eval('create_uid')
Not(In(Id('res','group_admin'), Eval('groups', [])))

```

They work well in Tryton 4.x, but do not work in Tryton 5.x.  
What is wrong with them?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 28, 2020, 5:59pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/2 "2020-02-28T17:59:19Z")

</div>

> [@bell](#):
>
> What is wrong with them?

Please provide more information. What is wrong? What is the current behavior and what is the expected?

I guess you were using the implicit user context as field instead of using evaluating explicitly the ‘context’.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [February 29, 2020, 11:43am UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/3 "2020-02-29T11:43:08Z")

</div>

> [@bell](#):
>
> Eval(‘\_user’) != Eval(‘create\_uid’)

This condition determines that the user did not create the record.

> [@bell](#):
>
> Not(In(Id(‘res’,‘group\_admin’), Eval(‘groups’, [])))

This condition determines that the user is not a member of Administration group.

These conditions work in Tryton 4.x, but do not work in Tryton 5.x.  
The name ‘\_user’ you advised here:

> **[Redirecting to Google Groups](https://groups.google.com/forum/#!searchin/tryton-dev/Eval(_user)%7Csort:date/tryton-dev/-LaH1CUAMBs/qCJjBk60Kw8J)**

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 29, 2020, 11:46am UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/4 "2020-02-29T11:46:01Z")

</div>

Indeed there is no more implicit fallback to `context`. `context` must be explicitly evaluated like `Eval('context', {}).get('user')`.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [February 29, 2020, 12:14pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/5 "2020-02-29T12:14:18Z")

</div>

> [@ced](#):
>
> Indeed there is no more implicit fallback to `context` .

But we do not need `context` in this case.  
These are system names `create_uid`, `user`, `groups`, `group_admin`, aren’t they?  
What about the current user? Do we need to use `user` name or `_user` name?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 29, 2020, 12:18pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/6 "2020-02-29T12:18:27Z")

</div>

> [@bell](#):
>
> These are system names

There are no “system names”, only record and context, since [Rationalize context usage in client (#7072) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue7072)

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [March 2, 2020, 6:18pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/7 "2020-03-02T18:18:12Z")

</div>

> [@ced](#):
>
> There are no “system names”, only record and context

Thus, we have to define a context model for our model only in order to get the values of current user, user groups, etc? Is there another way?

---

<div class="post-metadata">

### Author: ![oscarQ](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/oscarq/32/413_2.png) [@oscarQ](https://discuss.tryton.org/u/oscarQ)
#### Post date: [March 3, 2020, 10:27am UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/8 "2020-03-03T10:27:44Z")

</div>

> [@bell](#):
>
> Is there another way?

I don’t know if it is the best way to solve this problem but as you already have the current employee in the context so you can create a functional field that returns the current user or the groups the user belongs to depending on the employee and then use this functional field in the PYSON statements

---

<div class="post-metadata">

### Author: ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)
#### Post date: [March 3, 2020, 11:01pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/9 "2020-03-03T23:01:35Z")

</div>

> [@bell](#):
>
> > [@ced](#):
> >
> > There are no “system names”, only record and context
> 
> Thus, we have to define a context model for our model only in order to get the values of current user, user groups, etc? Is there another way?

AFAIK what @ced tries to explain is you need to use explicit context on pyson.  
As an example, the statement:  
`Eval('groups')`  
should be replace by  
`Eval('context', {}).get('groups')`

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [March 5, 2020, 6:45pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/10 "2020-03-05T18:45:05Z")

</div>

> [@oscarQ](#):
>
> you can create a functional field that returns the current user

Functional field will be evaluated for each record.  
But the current user is the same for all records.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [March 5, 2020, 6:57pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/11 "2020-03-05T18:57:50Z")

</div>

> [@sergyo](#):
>
> `Eval('context', {}).get('groups')`

This statement works, so the “system name” `groups` still exists. 🙂

> [@ced](#):
>
> `Eval('context', {}).get('user')` .

We have not added the name `user` to the context, so this statement does not work.

It seems the best solution is to add the current user to the user context fields:

```
class User(metaclass=PoolMeta):
    __name__ = 'res.user'
    user = fields.Function(fields.Integer('User'), 'get_user')

    @classmethod
    def __setup__ (cls):
        super(User, cls). __setup__ ()
        cls._context_fields.append('user')

    def get_user(self, name):
        return Transaction().user

```

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [April 4, 2020, 6:57pm UTC](https://discuss.tryton.org/t/pyson-statements-in-tryton-5-x/2387/12 "2020-04-04T18:57:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
