| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 134 |
| Technical Name |
direct_download_base |
| License | OPL-1 |
| Website | https://odoootips.com |
| Versions | 17.0 18.0 19.0 |
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 134 |
| Technical Name |
direct_download_base |
| License | OPL-1 |
| Website | https://odoootips.com |
| Versions | 17.0 18.0 19.0 |
Direct Download Base
Download large reports (Excel/PDF/CSV) using less memory. The file is generated on disk and delivered through a download link.
Benefits
- Better for heavy reports (kardex, stock moves, valuations, etc.).
- Avoids huge base64 data in RAM (more stable / lower memory usage).
- Faster than saving into Binary fields or attachments just to download.
Note: Excel has a limit of 1,048,576 rows per sheet (Microsoft Excel limitation).
Standard Odoo vs this module
- Standard: usually uses Binary/base64 (more RAM) or ir.attachment.
- Here: the file is written to disk and downloaded via URL (no base64).
- “One-shot” download: the file is removed when the download starts.
How to use it (the most important part)
- 1) Add dependency: direct_download_base
- 2) Inherit the mixin: direct.download.mixin
- 3) Generate the XLSX writing to output.part_path
- 4) Return: return output.action()
Minimal example (XLSX):
# __manifest__.py (your module)
# "depends": ["direct_download_base", ...]
import xlsxwriter
from odoo import models, _
class MyWizard(models.TransientModel):
_name = "my.wizard"
_inherit = ["direct.download.mixin"]
def action_export(self):
self.ensure_one()
output = self.dd_output_xlsx(_("Report") + ".xlsx")
wb = xlsxwriter.Workbook(output.part_path, {
"constant_memory": True,
"default_date_format": "dd/mm/yyyy",
})
ws = wb.add_worksheet("Report")
ws.write(0, 0, "Hello")
wb.close()
return output.action()
Permissions: Odoo must be able to write to data_dir.
Temp files are stored in: data_dir/direct_download/<dbname>/
Tip: you don’t need output.seek(0) (that only applies to BytesIO/base64).
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