跳至內容
選單
此問題已被標幟
1 回覆
1045 瀏覽次數
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.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
10月 24
1268
2
7月 25
1647
1
3月 25
1190
1
12月 24
1080
1
12月 24
1462