To download any binary file in Odoo10 following is the link:
http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>
module_name - the name of the model with the Binary field
field_name - the name of the Binary field
object_id - id of the record containing particular file.
field_filename - name of a Char field containing file's name (optional).
So if you want to call a function on button click and download the file, code is as follow:
file_url = "http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>"
return {
'type': 'ir.actions.act_url',
'url': file_url,
'target': 'new'
}
In Reports or web page, you can use it as:
<t t-foreach="files" t-as="f">
<tr>
<td><t t-esc="f.name"/></td>
<td><a t-attf-href="/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>">Download</a></td>
</tr>
</t>
Where files is a list of files
Thanks!!!!!!!!! Enjoy Programming!! :)
Hello, good afternoon, thank you very much for the comment that has helped me a lot. But I tried to do it and it gives me error the route, directly writing the route in the browser if it works but already in the code does not work
ReplyDeleteThank you
ReplyDeleteThank u
ReplyDeleteNice
ReplyDelete