Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
1998 Vizualizări

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?

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
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 Răspunsuri Vizualizări Activitate
0
sept. 24
1142
1
iun. 24
1475
1
mai 24
1686
3
mai 24
1907
1
mai 25
1309