コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
1989 ビュー

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.

関連投稿 返信 ビュー 活動
0
9月 24
1137
1
6月 24
1475
1
5月 24
1684
3
5月 24
1905
1
5月 25
1307