Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
9298 Lượt xem

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 :)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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..

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 24
1113
0
thg 8 23
2484
1
thg 12 22
2200
0
thg 7 21
2559
4
thg 8 17
13029