1

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.

2
  • Are you sure the PDF will never change? Sounds more like a changeable binary field on res.company or a char field with an URI. Commented Dec 13, 2023 at 9:14
  • @CZoellner It can be changed in the future by me changing the file in the module, but the filename will stay the same -- just essentially update the file. The point is that the file is not supposed to be changable by users. Commented Dec 13, 2023 at 9:17

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

4 Comments

every file should work on odoo-site. there's probably something in the used browser blocking some files.
@CZoellner You mean that there are going to be some files that get blocked by browser?
i hope so, like .pdf.exe but probably not :/
Okay. So for future readers, be wary that this method may likely have security issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.