Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

downloading text file, how to set the correct URL?

Avatar
odoo
Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

Hi,

You can try this following code

attachment_id = fields.Many2one('ir.attachment', string='Attachment', help='Attachment')
def download_attachment(self):
    return {
        'type': 'ir.actions.act_url',
        'url': '/web/image?model=ir.attachment&field=datas&id=%s&filename=%s' % (self.attachment_id.id, self.attachment_id.name),
    }

Regards

2 Comments
Avatar
Discard
Avatar
odoo
-

this attachment results empty, how can I put my text file on it?

Avatar
odoo
-

I solved with this code:

self.attachment_id = self.env['ir.attachment'].create({
'name': 'file.txt',
'type': 'binary',
'datas': base64.b64encode(data.encode()),
'res_id': self.id,
'mimetype': 'text/plain'
})

now the url works, thank you, really appreciated