Client Action File Download
by Steven Marp https://apps.odoo.com/apps/modules/browse?author=Steven Marp$ 5.00
Client Action File Download
Download Files Programmatically Without Opening Blank Tabs
Seamless UX
No annoying empty browser tabs left open, and no page reloads that reset the user interface state.
No Popup Wizards
Trigger downloads with a single click. No need to build temporary transient model wizards with download links.
Standard & Custom fields
Supports both standard ir.attachment records and any custom binary fields on your custom models.
Usage Examples
Simply return the action dictionary from your Python method:
1. Download an Attachment Record
return {
'type': 'ir.actions.client',
'tag': 'file_download',
'params': {
'id': attachment.id,
'download': True
}
}
2. Download from a Binary Field
return {
'type': 'ir.actions.client',
'tag': 'file_download',
'params': {
'model': self._name,
'field': 'datas',
'id': self.id,
'filename': 'myfile.csv',
'download': True
}
}
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 36 |
| Technical Name |
sm_action_file |
| License | OPL-1 |
| Website | https://apps.odoo.com/apps/modules/browse?author=Steven Marp |
Client Action File Download
Triggers File Download from Server Action
This module allows developers to trigger a file download from backend server actions, Python methods, or buttons.
Description
Odoo backend actions normally require opening new browser tabs or wizard forms to download files. This module registers a client action handler (file_download) that triggers a direct asynchronous download of the target file via JavaScript, maintaining a seamless user experience.
Views / Web Assets
- Registers file_download client action in Odoo's actions registry.
- Injected into web.assets_backend.
Dependencies
- web
Demonstration / Sample Code
Attachment Record
To download an ir.attachment record, return the client action with the attachment's database ID:
action = { 'type': 'ir.actions.client', 'tag': 'file_download', 'params': { 'id': attachment.id, 'download': True } }
Other Binary Field
To download a binary field from a specific model/record, pass the model name, field name, record ID, and filename details:
action = { 'type': 'ir.actions.client', 'tag': 'file_download', 'params': { 'model': self._name, 'field': 'datas', 'id': self.id, 'filename': self.filename, 'filename_field': 'filename', 'download': True } }
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module