How to make the client download a static file from a custom module on clicking a button?

79 Views Asked by At

Odoo 14 Community Edition

I have a custom module with a custom model inside it.

I created a custom view. It is working correctly.

Now that I need to add a button that let the client download a static file from the server.

The file should be put in the module folder, which I am still not sure where to put it, because of modularization.

Assume the button is created with a method for it correctly, how do I implement this and where should I put the file in order for it to work?

Note: It is just a normal PDF file. Think of it as a button to download a manual document.

1

There are 1 best solutions below

4
On BEST ANSWER

Return this object in the method of the button.

def download_static_file(self):
    return {'type': 'ir.actions.act_url', 'url': '/your_module_name/static/src/target_file.pdf', 'target': 'self'}

Also, put the file in the path above properly. I have tested .pdf and .xlsx. They both work.