Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2007 Widoki

Hi,

I set an automatic action to send an email when a sale order is created, it works correctly but for some orders I need send email only if specific fields are filled. 


My current solution is to set email destination as None if field is empty in the model, but i don't like it

${ (object.partner_id.email if object.x_studio_myfield == 'YES' else None)|safe}

Is there a better solution?

Thanks 


Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can change the ‘Action to do’ in the automated action to ‘Execute Python Code’ instead of ‘Send Email’.
Then the give the following python code.

if record.x_studio_myfield == 'YES':
    mail_template = env.ref('sale.email_template_edi_sale')
    mail_template.send_mail(record.id, force_send=True)

You can provide the required email template’s XML ID inside env.ref(‘...’).
In order to find the XML ID of email templates you can enable developer mode , go to Settings > Technical > Email > Templates , select the required template , click on debug tool and click on ‘View Metadata’.
Another suggestion is that you can create a boolean field instead of the character field ‘x_studio_myfield’ and use the python code as:

if record.x_studio_my_boolean_field:
    mail_template = env.ref('sale.email_template_edi_sale')
    mail_template.send_mail(record.id, force_send=True)

Regards

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
5
lut 25
7338
0
sty 17
2944
3
lut 25
8667
Automated emails Rozwiązane
3
wrz 24
8137
2
lip 24
4511