This question has been flagged
6 Replies
10812 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?


Avatar
Discard
Best Answer

Hi,

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)

${object.get_partner_ids(object.user_ids)}


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(']', '')


bye

Avatar
Discard
Author Best Answer

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

    ${object.get_partner_ids(object.user_ids)}
  4. Also, could you tell me why the additional char field is required?

Thanks again !

Avatar
Discard

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

Author

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.

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

Best Answer

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(']', '')
Avatar
Discard