| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 27 |
| Technical Name |
base_xlsx_helper |
| License | LGPL-3 |
Base XLSX Helper by Fort Matrix Protocol
The Ultimate Technical Tool for In-Memory Excel Generation
Say goodbye to temporary files and bloated databases! Base XLSX Helper is a pure, lightweight technical module that provides an AbstractModel for generating high-quality Excel files directly in memory.
Key Features
- 100% In-Memory: Uses
io.BytesIO()to generate files without touching the disk. - AbstractModel Design: Doesn't create unnecessary database tables. Just call it from anywhere in your code!
- Smart Formatting: Automatically detects long numeric strings (like EANs or Tracking Numbers) and formats them as text to prevent Excel from converting them to scientific notation (e.g., 1.23E+15).
- Ready for Email & Attachments: Returns raw
Base64, ready to be passed directly toir.attachment.
Real-World Example: Server Action for Stock Picking
Here is a practical example of how you can use this helper inside an Odoo Server Action (e.g., on Delivery Orders / stock.picking). This script collects product data, generates the XLSX file on the fly, and attaches it instantly:
# 1. Prepare data from the current record (e.g., Delivery Order)
headers = ['Order', 'Product', 'SKU', 'EAN', 'Stock', 'Unit']
data_rows = []
sale_name = record.sale_id.name if record.sale_id else ''
attachment_ids = []
for line in record.move_ids_without_package:
data_rows.append([
sale_name,
line.product_id.name or '',
line.product_id.default_code or '',
line.product_id.barcode or '',
line.quantity,
line.product_uom.name or ''
])
# 2. Generate the XLSX file on the fly using the custom helper
xlsx_base64_bytes = env['export.xlsx.helper'].generate_xlsx(headers, data_rows, sheet_name='WZ_Dane')
# 3. Create the attachment in the database
attachment_xlsx = env['ir.attachment'].create({
'name': 'Dane_WZ_%s.xlsx' % record.name.replace('/', '_'),
'type': 'binary',
# Decode bytes to string for safe database storage (crucial for JSON/XML-RPC)
'datas': xlsx_base64_bytes.decode('utf-8'),
'mimetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
})
# 4. Append to your attachments list (ready to be sent via email!)
attachment_ids.append(attachment_xlsx.id)
Support & Contact
Developed by Fort Matrix Protocol.
If you need custom development or have questions, feel free to reach out via our e-mail fortmatrixprotocol@gmail.com
Please log in to comment on this module