Skip to Content
Menu
This question has been flagged
1 Reply
8156 Views

Hello

I made a custom module that load data from email.template but the problem is that data not rendering and just showing as code like ${object.date} instead of showing date. so any one can say how i can handle this, what should i add to my custom module to get able to render email template objects?

i get data from email.template with a simple way like below code

template_id = fields.Many2one(
'email.template',
string='Template',
track_visibility='onchange',)
and then getting the body value with onchange like below

self.note = self.template_id.body_html

Thanks :)

Avatar
Discard
Best Answer

Hi Berctain,

To render email template object in your module you need to follow bellow steps:

ir_model_obj = self.env['ir.model.data']

# browse template reference from model data

template_browse = ir_model_obj.get_object_reference('module_name', 'email_template_id')[1] 

# browse email template 

email_template_obj = self.env['mail.template'].browse(template_browse)

# Generate email template for specific record

values = email_template_obj.generate_email(res_id) # it is to generate email for specific object record


Refer: https://www.odoo.com/forum/help-1/question/correct-way-to-e-mail-custom-html-record-in-function-96570

https://www.odoo.com/forum/help-1/question/qweb-templating-python-side-access-survey-user-input-model-on-survey-template-using-t-field-93882


Hope it will useful for you..

Avatar
Discard
Author

Hello

Note worked.

do these are miss typed or some thing?

'email_template_id' instead of 'email_template'

or

self.env['mail.template'] instead of self.env['email.template']

and the first error i get is this >> the External id not found res_cores_int.email_template_id even when i change it too email.template its same

res.core.int is my module name

Related Posts Replies Views Activity
0
Oct 24
124
0
Aug 23
1365
1
Dec 22
1168
0
Jul 21
1374
4
Aug 17
11554