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.
Before installing this module, make sure to install the following libraries:
pip install docxcompose docxtpl htmldocx
For usage instructions, you can refer to the following video: Link

Example template use for sale order: Link
Documentation on writing syntax in the document: Link
To call and write the field name, use the following format: {{docs.field_name}}, starting with the word "docs".
{{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 Mm.{{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: The functions will be updated as needed.
lang default is lang='id_ID' change if need, example = {{spelled_out(docs.numeric_field, lang='en_US')}}
There are three modes for generating .docx reports:
- composer: Generate a
.docxfile - zip: Generate a
.zipcontaining the.docxfile - pdf: Convert the
.docxfile to PDF using LibreOffice
If you want to use the "pdf" option, ensure that LibreOffice is installed. Then set the LibreOffice path in Settings => Technical => Parameters => System Parameters, and search for the key default_libreoffice_path. Set the value according to your LibreOffice installation path:
- Linux:
/usr/bin/libreoffice - Windows:
C:\Program Files\LibreOffice\program\soffice.exe
We welcome any feedback and suggestions, especially for improving this module. Thank you!