Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1987 Переглядів

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?

Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Автор

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 Відповіді Переглядів Дія
0
вер. 24
1136
1
черв. 24
1474
1
трав. 24
1684
3
трав. 24
1904
1
трав. 25
1307