Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1985 Zobrazení

Hi All,


I am using Odoo15, in which I have a requirement to change the email subject of a custom template based on a condition. The template is designed in code the itself.

My email subject is as follows: This is a test mail for {{ object.my_field_name }}

For condition check, 

if condition_satisfies: subject = "Condition Satisfied - " + subject

else: subject = subject.


In case of condition satisfied, while I am triggering the mail, the subject is coming as 

Condition Satisfied - This is a test mail for {{ object.my_field_name }} 

instead of actual value of my_field_name.


Do anyone have a solution to resolve this?

Avatar
Zrušit
Nejlepší odpověď

Hi,


Instead of adding the condition in the template, please include the following in your action_send_email function:



template_id = self.env.ref('your_module'

'template_id')

email_vals = {

'message_type': 'notification',

'is_notification': True,

'model': 'your.model'}


subject = f"Condition Satisfied - {self.my_field_name}" if condition else self.my_field_name

email_vals['subject'] = subject

template_id.with_context(data=data).send_mail(res_id, email_values=email_vals,

                                                              force_send=True)



Here, res_id is the record ID.


Hope it helps

Avatar
Zrušit
Autor

Thank you for the response.
But I need this to work for all the mail triggers even for the default email triggers where ever we are using mail.compose.message.
So I created an onchange method for template where the subject will be changed accordingly.
There is no issue if the subject is a plain text. But if there is any object, I'm not getting the value.

Related Posts Odpovědi Zobrazení Aktivita
0
zář 24
1136
1
čvn 24
1474
1
kvě 24
1684
3
kvě 24
1904
1
kvě 25
1307