Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
1974 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä

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.

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
syysk. 24
1134
1
kesäk. 24
1472
1
toukok. 24
1682
3
toukok. 24
1902
1
toukok. 25
1307