# Addresses from Many2Many mymodel--party.party in E-Mail template

**URL:** <https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124>\
**Category:** User\
**Created:** [December 14, 2024, 5:30pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124 "2024-12-14T17:30:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gruenfischer](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@Gruenfischer](https://discuss.tryton.org/u/Gruenfischer)\
**Post date:** [December 14, 2024, 5:30pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/1 "2024-12-14T17:30:10Z")

</div>

Hi,  
I would like to create an e-mail template for a custom model.  
the model hast 2 fields. One field many2One to a party.party and one field Many2Many towards party.party.

In the e-mail template I am offered to add a field for “recipients”. When clicking, it offers me only the many2one field, the created\_by, edited\_by **but not** the may2many.

Is there a way to add the Many2many partys as recipients?  
Or is there a different approach?

Regards Jakob

---

<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:** [December 14, 2024, 5:46pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/2 "2024-12-14T17:46:55Z")

</div>

Which email template are you talking about?

---

<div class="post-metadata">

**Author:** ![Gruenfischer](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@Gruenfischer](https://discuss.tryton.org/u/Gruenfischer)\
**Post date:** [December 14, 2024, 8:59pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/3 "2024-12-14T20:59:34Z")

</div>

I am talking about:  
Administration → Userinterface-\> Actions-\> E-Mail templates.

---

<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:** [December 14, 2024, 9:44pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/4 "2024-12-14T21:44:16Z")

</div>

Indeed the selection constraint is based on the `relation` value of the field.  
But for `Many2Many` the `relation` is the relation table and not the target so they are not available.  
I filled [Can not select Many2Many as recipients of email template (#13756) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/13756) if someone wants to improve the support.

---

<div class="post-metadata">

**Author:** ![Gruenfischer](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@Gruenfischer](https://discuss.tryton.org/u/Gruenfischer)\
**Post date:** [December 15, 2024, 11:05am UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/5 "2024-12-15T11:05:02Z")

</div>

I saw that there is the possibility to use a PYSON STatement in the char field. I tried with  
`Eval("self.parents", []),` where parents is the m2m field linking party.party. But it seems to return an empty list.  
Is it possible that way and i am just having a mistake i the statemet or does that not work at all?

---

<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:** [December 15, 2024, 11:30am UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/6 "2024-12-15T11:30:09Z")

</div>

Indeed using a `PYSON` expression should work.

---

<div class="post-metadata">

**Author:** ![Gruenfischer](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@Gruenfischer](https://discuss.tryton.org/u/Gruenfischer)\
**Post date:** [December 15, 2024, 7:46pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/7 "2024-12-15T19:46:09Z")

</div>

Do you have a hint for me, how to create that pyson statement, please?  
`(self.parents,[] )` Does not give me a result, but in Trytond-console I can navigate to the model “member”, that should be the model in “self” and get two party-records with member.parents.

---

<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:** [December 15, 2024, 8:10pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/8 "2024-12-15T20:10:35Z")

</div>

It shoudl be `Eval('self', {}).get('parents', [])`

---

<div class="post-metadata">

**Author:** ![Gruenfischer](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@Gruenfischer](https://discuss.tryton.org/u/Gruenfischer)\
**Post date:** [December 16, 2024, 6:11pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/9 "2024-12-16T18:11:54Z")

</div>

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

Unfortunately that does not give a result. The statement is rewritten to `Get(Eval("self", {}), "parents", [])` when saving the object.  
When I use the template from the member model of the cliental- , it does not pull the values.  
I double checked in the Trytond-Console:

```auto
>>> env = EvalEnvironment(mem, Member)
>>> mem.parents
(Pool().get('party.party')(4), Pool().get('party.party')(3))
>>> b= Eval('parents',[])
>>> PYSONDecoder(env).decode(PYSONEncoder().encode(b))
[4, 3]

```

The statement, as far as I understand, should return the list [4, 3].

---

<div class="post-metadata">

**Author:** ![Gruenfischer](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/g/3be4f8/32.png) [@Gruenfischer](https://discuss.tryton.org/u/Gruenfischer)\
**Post date:** [December 21, 2024, 2:05pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/10 "2024-12-21T14:05:08Z")

</div>

In case, someone else has that problem.  
I read somewhere else in the forum, the statement must return a list of strings containing e-mail addresses. I read as well, that iteration over al list of objects I pyson Is not possible.

I now create a Function Field on\_change\_with depending on the m2m field, that extracts a char list of

` name <email>,`

That solution is working.

---

<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 22, 2024, 2:05pm UTC](https://discuss.tryton.org/t/addresses-from-many2many-mymodel-party-party-in-e-mail-template/8124/11 "2024-12-22T14:05:57Z")

</div>

Closed on December 22, 2024, 2:05pm UTC

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