Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1030 มุมมอง
post.twitter_preview = self.env.ref('social_medias.twitter_preview').render({
AttributeError: 'ir.ui.view' object has no attribute 'render'

//Odoo 9 code 

@api.depends('message', 'scheduled_date', 'image_ids')
def _compute_twitter_preview(self):
for post in self:
post.twitter_preview = self.env.ref('social_medias.twitter_preview').render({
'message': post.message,
'images': [
image.datas if not image.id
else base64.b64encode(open(image._full_path(image.store_fname), 'rb').read()) for image in post.image_ids
]
})


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi,

This issue is resolve 

In Odoo17 render method doesn't work like above way you need to add this way below.

@api.depends('message', 'scheduled_date', 'image_ids')
def _compute_twitter_preview(self):
for post in self:
template = self.env.ref('social_medias.twitter_preview').id
values = {
'message': post.message,
'images': [
image.datas if not image.id
else base64.b64encode(open(image._full_path(image.store_fname), 'rb').read()) for image in post.image_ids
]
}
post.twitter_preview = self.env['ir.qweb']._render(template, values)

You need to use 

self.env['ir.qweb']._render(template, values)

and add xml_id of that specific template and second argument is dict of values.

i refer odoo addons ir.ui.view.py file like this way

Its complete work.

Thanks.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 24
1239
2
ก.ค. 25
1630
1
มี.ค. 25
1181
1
ธ.ค. 24
1070
1
ธ.ค. 24
1447