This question has been flagged
2 Replies
14007 Views

How to Download attached files in ir_attachment model in ODOO website.?? 

Passed values in controller like below but I dont have an Idea to fetch doc via website

attach = request.env['ir.attachment'].search([('res_id','=',order.id)],limit=1)

        values = {

            'website_sale_order': order,

            'file_attach':attach.name,

            'w_p': v1

        }

In xml:

<strong>Attachments:  </strong> <a t-esc="file_attach"/> it prints filename but cant able to link or downlad

Avatar
Discard

HI, check with this module, you will get a solution if you go through this code

https://www.odoo.com/apps/modules/10.0/website_event_attachements/

Best Answer

Hi Annadurai,

For downloading the attachments from the website, you can add  xml code like this,

<t t-foreach="attachments" t-as="attachment">
<a t-att-href="'/attachment/download?attachment_id=%i' % attachment.id">
<span t-esc="attachment.name" class="fa fa-download"/>
</a><br/>
</t>

To get more info you can check with the working of this community module,

Event Attachments on Website


Thanks

Avatar
Discard
Author

Thanks.

Or alternatively (tested in V13):

<a t-attf-href="/web/content/#{attachment.id}?download=true&amp;access_token=#{attachment.access_token}">

<span t-esc="attachment.name" class="fa fa-download"/>

</a>