How to download any file on button click ?
We at Emipro, got this question numerous times from different Odoo developers. So here I am giving the step by step guidance how to do this.
Here all of below code is written in Odoo V8.
Step 1 : Create a method inside your regular model and return URL.
Here I have returned URL with model and some other necessary informatons, Now in next step i will catch that URL to an another controller kind of method.
( just like file you can see in /web/controllers/main.py )
Step 2 : Make a controller class and catch that url and do process for download excel file.
In above method I have got the ID from url and then applied some calculation and return the http response from request. Whatever values I have passed from wizard to controller method, I will get them on controller method and in that controller method i will do necessary process and return file directly.
See below, I have passed model, field, id and filename from url
def download_document(self,model,field,id,filename=None, **kw):
I have returned Excel file but you can return any kind of file and even an attachment from database binary field too.
By apply code like above, you will able to return any file on button click without intervention of binary field.I hope this post will add extra spice into your knowledge and make your Odoo technical understanding more delicious.
Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions. We are just an inch away from you by email firstname.lastname@example.org or a tweet to @EmiproTech
Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. Our customers are companies of all sizes ranging from startups to large enterprises who realize that they need a professional internet solution to generate revenue streams, establish proper communication channels, to achieve desired goals and streamline business operations. [....] Read More