Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
1033 Vizualizări
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
]
})


Imagine profil
Abandonează
Autor Cel mai bun răspuns

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.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
oct. 24
1239
2
iul. 25
1633
1
mar. 25
1182
1
dec. 24
1071
1
dec. 24
1451