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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
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?
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
Thanks Cyril ! This is excellent.
Just a couple of changes that I had to make from my end:
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.
partner.id should be partner_id.id
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)}
Also, could you tell me why the additional char field is required?
Thanks again !
could yoy explain what you said : the additional char field ?
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
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(']', '')
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
Send email with python
Solved
|
|
4
Jul 24
|
17437 | |
|
1
Feb 24
|
905 | ||
|
1
Jul 23
|
1634 | ||
|
3
Dec 23
|
17560 | ||
Failed to render template
Solved
|
|
1
Feb 22
|
4392 |