Tuesday, 6 June 2017

Odoo: Download Binary File in v10

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!! :)

No comments:

Post a Comment

Thanks for your valuable comments.

Odoo 10: Close wizard and open standard form

Hi, Today we are going to learn how to open standard form after saving data in wizard. Let's say I have created an wizard to fill bas...