Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
1025 Представления
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
1238
2
июл. 25
1630
1
мар. 25
1180
1
дек. 24
1070
1
дек. 24
1444