| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
Discuss (mail)
|
| Lines of code | 578 |
| Technical Name |
alnas_docx |
| License | LGPL-3 |
| Website | https://github.com/alienyst |
| Versions | 14.0 16.0 17.0 18.0 19.0 |
Docx Report Generator
The Docx Report Generator is a module that helps you create reports using only a .docx template and Jinja syntax.
This module inspired from Report Xlsx.
Prerequisites
Before installing this module, make sure to install the following libraries:
For Python 3.12 and above
pip install git+https://github.com/tvuotila/docxcompose.git@hotfix/90 docxtpl htmldocx
For Below Python 3.12
pip install docxcompose docxtpl htmldocx
Usage
For usage instructions, you can refer to the following video: Link
Example template use for sale order: https://github.com/alienyst/alnas-docx/raw/16.0/alnas_docx/static/description/example/example.docx
Documentation on writing syntax in the document: https://docxtpl.readthedocs.io/en/stable
Field Naming Convention
To call and write the field name, use the following format: {{docs.field_name}}, starting with the word "docs".
Useful Functions (Indonesian Language as default)
{{spelled_out(docs.numeric_field)}}: Spell out numbers{{formatdate(docs.date_field)}}: Format dates{{parsehtml(docs.html_field)}}: Render HTML content as plain text{{p html2docx(docs.html_field)}}: Render HTML as subdocument{{convert_currency(docs.monetary_field, docs.currency_id)}}: Show monetary field{{render_image(docs.image_field)}}or{{render_image(docs.image_field, width=10, height=10)}}: Render image in millimeters{{r rich_text(docs.text_field)}}: Show Rich Text{{p add_subdoc(docs.docx_binary_field)}}: Add Subdocument{{replace_image('file_name_in_word', docs.image_field)}}: Replace the dummy picture in word document with another one{{replace_media('file_name_in_word', docs.image_field)}}: Unlike replace_pic() method, dummy_header_pic.jpg MUST exist in the template directory when rendering and saving the generated docx.{{replace_embedded('file_name_in_word', docs.binary_field)}}: It works like medias replacement, except it is for embedded objects like embedded docx{{replace_zipname('file_path_in_word', docs.binary_field)}}: replace_embedded() may not work on other documents than embedded docx. Instead, you should use zipname replacement
Note: These functions will be updated as needed.
The default language is lang='id_ID', but it can be changed. For example: {{spelled_out(docs.numeric_field, lang='en_US')}} {{formatdate(docs.numeric_field, lang='en_US')}} {{convert_currency(docs.numeric_field, locale='en_US')}}
for format_date and convert_currency, you can use all parameter from babel function Babel Documentation
Docx Output Modes
There are three modes for generating docx reports:
- composer => Generate a docx file
- zip => Generate a zip containing the docx file
- pdf => Convert the docx file to PDF using LibreOffice
If you want to use the 'pdf' option, ensure you have installed LibreOffice. Then set the LibreOffice path in Settings => Technical => Parameters => System Parameters, and search for the key default_libreoffice_path. Set the value according to the LibreOffice installation path:
- Linux:
/usr/bin/libreoffice - Windows:
C:\Program Files\LibreOffice\program\soffice.exe
Credit
Special thanks to Salvo (salvorapi) for helping to update the code from Odoo 16 to Odoo 17.
Feedback
We welcome any feedback and suggestions, especially for improving this module. Thank you!
Please log in to comment on this module
There are no ratings yet!
Import image
Its no import image
Import image
Hi @Andre,
To display an image, you can use the following jinja syntax:
{{render_image(docs.image_field)}} or {{render_image(docs.image_field, width=10, height=10)}}: Displays an image from an Odoo field, with the option to set the size in millimeters.
{{replace_image('file_name_in_word', docs.image_field)}}: Replaces a placeholder image in a Word document with the one from an Odoo field.
Thank you.