콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1071 화면
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
1312
2
7월 25
1711
1
3월 25
1266
1
12월 24
1121
1
12월 24
1552