| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
Discuss (mail)
|
| Lines of code | 577 |
| 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
Add product documents to the word
Hello,
I downloaded this app to integrate it in my odoo. I started to customize the template and I am searching how I could add the product document to the word (product.document)? I would like to add a doc as we do with the quote builder in the native pdf module. Is their any way do to it?
Thank you in advance
Re: Add product documents to the word
Hello,
To add a docx document in docx report file you can use subdocument
Example :
{{p add_subdoc(docs.docx_binary_field)}}
Thank you.
Re: Version 18
Hello,
Thank you for your reply.
I managed to install the libraries on a Windows system. However, when I try to install the module in Odoo, I get the message 'Something went wrong...'
Is this module already compatible with version 18?
Looking forward to your reply.
Re: Re: Version 18
Hello,
Yes, the module is compatible with Odoo 18.
Could you please copy the exact error message that appears when you try to install it? That will help us identify the issue more precisely.
Thank you.
Version 18
Hello,
I'm trying to install this module for V18. It instructed me to install de required libraries (docxtpl htmldocx), which I did. However, I still receive the notification: 'External dependency docxtpl not installed: No package metadata was found for docxtpl'.
Am I missing a step to V18?
Looking forward to your reply.
Re: Version 18
Hello,
Thank you for contacting us. I believe the libraries are not installed in the same Python environment that Odoo is using. Please make sure to install docxtpl and htmldocx inside Odoo’s Python/virtualenv. For example:
> source /path_to_odoo/odoo-venv/bin/activate
> pip install docxtpl htmldocx
To check which Python environment your Odoo server is using, you can run:
> ps -aux | grep odoo
Don’t forget to restart the Odoo service after installing the libraries.
Thank you.