Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How set 'To' field of email template with a many2many field

Shawn Varghese
on 4/6/15, 7:07 AM 929 views

There are 2 parameters in the email templates:

To (Emails)

To (Partners)

I want to use a many2many fields variable for this. Something like ${object.user_ids}. Is there any way to do it?


Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 4/6/15, 10:19 AM


To (Emails) : 

'email_to': fields.char('To (Emails)', help="Comma-separated emailaddresses (placeholders may be used here)"),

To (Partners) :

'partner_to': fields.char('To (Partners)',

help="Comma-separated ids of recipient partners (placeholders may be used here)",

=> list of id of class res partner, not res users, but a user has a related partner

add in To (Partners)


in the class where is defined field user_ids, add the function used in ${object.get_partner_ids(object.user_ids)}

    def _get_partner_ids(self, cr, uid, user_ids) :

        return str([user.partner_id.id for user in user_ids]).replace('[', '').replace(']', '')


Lucas Huber
On 3/18/16, 12:02 PM

I have a similar case, but can't figure out how I get the correct partner ids. I have a message model that is related to project.project and I want to get the followers of the project into my mail.template.

Here is my code so far. I stuck at the relation between the field project.message_follower_ids and  res_partner.  (project.message_follower_ids is related to mail.followers -> res_id).

<field name="partner_to">${object.get_partner_ids(object.project_id.message_follower_ids)}</field>

@api.multi  # TODO get the followers of the active Scrum Project
def get_partner_ids(self, user_ids):
  return str([user_ids.ids]).replace('[', '').replace(']', '')
Shawn Varghese
On 4/7/15, 3:08 AM

Thanks Cyril ! This is excellent.

Just a couple of changes that I had to make from my end:

  1. The function name beginning with underscore (_get_partner_ids) had to be changed to just get_partner_ids because the private class was inaccessible from the template.

  2. partner.id should be partner_id.id

  3. Calling the function from template was defined without the cr,uid because that was raising issues for me

  4. Also, could you tell me why the additional char field is required?

Thanks again !

could yoy explain what you said : the additional char field ?

Cyril Gaspard (GEM)
on 4/7/15, 2:16 PM

This char field: 'partner_to': fields.char('To (Partners)', help="Comma-separated ids of recipient partners (placeholders may be used here)", It is not being used right? So I was wondering why it is required.

Shawn Varghese
on 4/8/15, 1:25 AM

it is not required, but you should have at least one email address, if you want use directy address a@a.com,...., use field, 'email_to', if you want use email field of a partner, use 'partner_to', bye

Cyril Gaspard (GEM)
on 4/14/15, 3:50 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 4/6/15, 7:07 AM
Seen: 929 times
Last updated: 3/18/16, 12:02 PM