# Using Pyson in email template

**URL:** https://discuss.tryton.org/t/using-pyson-in-email-template/3470
**Category:** User
**Created:** [November 19, 2020, 4:41pm UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470 "2020-11-19T16:41:03Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [November 19, 2020, 4:41pm UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/1 "2020-11-19T16:41:03Z")

</div>

I am still confused with using of Pyson.

For example I would like to retrieve a field behind a Many2One, for example the email field of the party from a sale, to fill in the recipient field of an email template (I know that I can do this by selecting the field party directly, but I’d like to do it in Pyson to understand the syntax).  
I tested  
`[Eval ('party.email', '')]` : it doesn’t return anything  
`[Eval ('self.party.email', '')]` : I have an error: Fault: ‘int’ object has no attribute ‘get’

Thanks for your help

---

<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: [November 19, 2020, 10:01pm UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/2 "2020-11-19T22:01:12Z")

</div>

This is because we use `EvalEnvironment` in place of `self`. So the relation fields are evaluated with their `id`. This limits a lot the possibilities so I think we should use directly the record.

---

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [November 19, 2020, 10:37pm UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/3 "2020-11-19T22:37:45Z")

</div>

> [@ced](#):
>
> This limits a lot the possibilities so I think we should use directly the record.

Sorry i don’t’ see how make that ☹

---

<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: [November 19, 2020, 10:53pm UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/4 "2020-11-19T22:53:01Z")

</div>

For me we could just remove the usage of `EvalEnvironment`.

---

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [November 20, 2020, 7:32am UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/5 "2020-11-20T07:32:27Z")

</div>

what I understood:  
in file: `ir/email.py`

```auto
[...]
#env['self'] = EvalEnvironment(record, record. __class__ )
env['self'] = record
[...]

```

With this Pyson string:  
`[Eval ('self.party.email', '')]` : I have an error: Fault: “sale.sale,36” has no attribute “get”

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [November 20, 2020, 7:45am UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/6 "2020-11-20T07:45:35Z")

</div>

> [@2cadz](#):
>
> With this Pyson string:  
> `[Eval ('self.party.email', '')]` : I have an error: Fault: “sale.sale,36” has no attribute “get”

Then you can use directly `self.party.email` without using Eval

---

<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: [November 20, 2020, 8:23am UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/7 "2020-11-20T08:23:48Z")

</div>

> [@2cadz](#):
>
> I have an error: Fault: “sale.sale,36” has no attribute “get”

Indeed PYSON Eval requires a EvalEnvironment.

> [@pokoli](#):
>
> Then you can use directly `self.party.email` without using Eval

I do not think so because it is a PYSON expression.

I guess you must write: `[Eval('self._parent_party.email', '')]`  
This is because the prefix `_parent_` is evaluated with a new `EvalEnvironment` instead of just `id`.

---

<div class="post-metadata">

### Author: ![2cadz](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/2cadz/32/130_2.png) [@2cadz](https://discuss.tryton.org/u/2cadz)
#### Post date: [November 20, 2020, 8:51am UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/8 "2020-11-20T08:51:19Z")

</div>

> [@ced](#):
>
> I guess you must write: `[Eval('self._parent_party.email', '')]`

Yes it works, thanks

> [@ced](#):
>
> This is because the prefix `_parent_` is evaluated with a new `EvalEnvironment` instead of just `id` .

Ok, and for example to reach the name field of the account receivable of a party (`self.party.account_receivable.name`) i must write: `Eval('self._parent_party._parent_account_receivable.name', '')` ?

---

<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: [December 20, 2020, 8:51am UTC](https://discuss.tryton.org/t/using-pyson-in-email-template/3470/9 "2020-12-20T08:51:20Z")

</div>

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