Skip to content

Commit 3e521a1

Browse files
committed
[ADD] report_docx
1 parent 2f366d6 commit 3e521a1

29 files changed

Lines changed: 1317 additions & 0 deletions

report_docx/README.rst

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
============
2+
DOCX reports
3+
============
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:79e0f48df24a25104ed7488dce18fa34f20814020b270bb7a7682746a4616596
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Alpha
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
20+
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_docx
21+
:alt: OCA/reporting-engine
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_docx
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows to provide docx files as report templates to generate
32+
docx reports.
33+
34+
.. IMPORTANT::
35+
This is an alpha version, the data model and design can change at any time without warning.
36+
Only for development or testing purpose, do not use in production.
37+
`More details on development status <https://odoo-community.org/page/development-status>`_
38+
39+
**Table of contents**
40+
41+
.. contents::
42+
:local:
43+
44+
Use Cases / Context
45+
===================
46+
47+
This module was developed because for some users it is easier to use the
48+
docx format for their templates.
49+
50+
As it uses a slightly different templating language, it is *not* a
51+
drop-in replacement for report_py3o.
52+
53+
It also does not provide any format conversions, though it should be
54+
pretty simple to write a glue module that converts the resulting docx
55+
files to formats supported by report_py3o.
56+
57+
Installation
58+
============
59+
60+
To install this module, you need to:
61+
62+
::
63+
64+
pip install docxtpl
65+
66+
Configuration
67+
=============
68+
69+
To configure this module, you need to:
70+
71+
1. Go to Settings / Technical / Actions / Report
72+
2. Create a new report with type DOCX
73+
3. Fill in the name of a model, ie ``crm.lead``
74+
4. Upload your DOCX file in the ``Template`` field
75+
5. To help with crafting expressions in the template, switch to the DOCX
76+
tab, select a record and fill in some expression. When happy with the
77+
result, copy the code into your template document. Don't forget to
78+
read the extensive documentation on the right hand side
79+
80+
Usage
81+
=====
82+
83+
To use this module, you need to:
84+
85+
1. Print some report created according to the configuration manual
86+
87+
Known issues / Roadmap
88+
======================
89+
90+
- support images and embedded objects
91+
- support concatenating docx files for multiple records
92+
- support embedding html
93+
94+
Bug Tracker
95+
===========
96+
97+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
98+
In case of trouble, please check there if your issue has already been reported.
99+
If you spotted it first, help us to smash it by providing a detailed and welcomed
100+
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_docx%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
101+
102+
Do not contact contributors directly about support or help with technical issues.
103+
104+
Credits
105+
=======
106+
107+
Authors
108+
-------
109+
110+
* Hunki Enterprises BV
111+
112+
Contributors
113+
------------
114+
115+
- Holger Brunn <mail@hunki-enterprises.com>
116+
(https://hunki-enterprises.com)
117+
118+
Other credits
119+
-------------
120+
121+
The development of this module has been financially supported by:
122+
123+
- The Open Source Company (https://tosc.nl)
124+
125+
Maintainers
126+
-----------
127+
128+
This module is maintained by the OCA.
129+
130+
.. image:: https://odoo-community.org/logo.png
131+
:alt: Odoo Community Association
132+
:target: https://odoo-community.org
133+
134+
OCA, or the Odoo Community Association, is a nonprofit organization whose
135+
mission is to support the collaborative development of Odoo features and
136+
promote its widespread use.
137+
138+
.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
139+
:target: https://github.com/hbrunn
140+
:alt: hbrunn
141+
142+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
143+
144+
|maintainer-hbrunn|
145+
146+
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/16.0/report_docx>`_ project on GitHub.
147+
148+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

report_docx/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import controllers
2+
from . import models

report_docx/__manifest__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2026 Hunki Enterprises BV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
3+
4+
{
5+
"name": "DOCX reports",
6+
"summary": "Create report templates in DOCX and receive DOCX files",
7+
"version": "16.0.1.0.0",
8+
"development_status": "Alpha",
9+
"category": "Reporting",
10+
"website": "https://github.com/OCA/reporting-engine",
11+
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
12+
"maintainers": ["hbrunn"],
13+
"license": "AGPL-3",
14+
"external_dependencies": {
15+
"python": ["docxtpl"],
16+
},
17+
"depends": [
18+
"mail",
19+
],
20+
"data": [
21+
"views/ir_actions_report.xml",
22+
"views/templates.xml",
23+
],
24+
"demo": [
25+
"demo/ir_actions_report.xml",
26+
],
27+
"assets": {
28+
"web.assets_backend": [
29+
"/report_docx/static/src/report_docx.esm.js",
30+
]
31+
},
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import report

report_docx/controllers/report.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2026 Hunki Enterprises BV
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
3+
4+
import json
5+
import logging
6+
7+
from jinja2 import exceptions as jinja2_exceptions
8+
9+
from odoo import http, tools
10+
11+
from odoo.addons.web.controllers import report
12+
13+
_logger = logging.getLogger(__name__)
14+
15+
16+
class ReportController(report.ReportController):
17+
@http.route(["/report_docx"], type="http", auth="user")
18+
def report_docx(self, report_name, ids=None, context=None, data=None, **kwargs):
19+
ids = ids and json.loads(ids) or []
20+
data = data and json.loads(data) or {}
21+
try:
22+
docx, ext = (
23+
http.request.env["ir.actions.report"]
24+
.with_context(**(context and json.loads(context) or {}))
25+
._render_docx(report_name, ids, data=data)
26+
)
27+
except jinja2_exceptions.TemplateError as e:
28+
_logger.exception("Error while generating report %s", report_name)
29+
return http.request.make_response(
30+
tools.html_escape(
31+
json.dumps(
32+
{
33+
"code": 200,
34+
"message": e.message,
35+
"data": http.serialize_exception(e),
36+
}
37+
)
38+
)
39+
)
40+
except Exception as e:
41+
_logger.exception("Error while generating report %s", report_name)
42+
return http.request.make_response(
43+
tools.html_escape(
44+
json.dumps(
45+
{
46+
"code": 200,
47+
"message": "Odoo Server Error",
48+
"data": http.serialize_exception(e),
49+
}
50+
)
51+
)
52+
)
53+
54+
report = http.request.env["ir.actions.report"]._get_report(report_name)
55+
filename = report._render_docx_filename(report, ids, data, ext)
56+
57+
return http.request.make_response(
58+
docx,
59+
headers=[
60+
(
61+
"Content-Type",
62+
"application/zip"
63+
if ext == "zip"
64+
else (
65+
"application/vnd.openxmlformats-officedocument"
66+
".wordprocessingml.document"
67+
),
68+
),
69+
("Content-Length", len(docx)),
70+
("Content-Disposition", http.content_disposition(filename)),
71+
],
72+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2026 Hunki Enterprises BV
3+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
4+
<data>
5+
<record id="report_ir_module_multi_mode_template" model="ir.actions.report">
6+
<field name="name">DOCX (one file)</field>
7+
<field name="model">ir.module.module</field>
8+
<field name="report_type">docx</field>
9+
<field name="report_name">ir_module_multi_mode_template</field>
10+
<field name="print_report_name">object.name</field>
11+
<field
12+
name="docx_template"
13+
type="base64"
14+
file="report_docx/static/examples/modules_multi_mode_template.docx"
15+
/>
16+
<field name="docx_multi_mode">template</field>
17+
<field name="binding_model_id" ref="base.model_ir_module_module" />
18+
</record>
19+
<record id="report_ir_module_multi_mode_zip" model="ir.actions.report">
20+
<field name="name">DOCX (zip if multiple)</field>
21+
<field name="model">ir.module.module</field>
22+
<field name="report_type">docx</field>
23+
<field name="report_name">ir_module_multi_mode_zip</field>
24+
<field name="print_report_name">object.name</field>
25+
<field
26+
name="docx_template"
27+
type="base64"
28+
file="report_docx/static/examples/modules_multi_mode_zip.docx"
29+
/>
30+
<field name="docx_multi_mode">zip</field>
31+
<field name="binding_model_id" ref="base.model_ir_module_module" />
32+
</record>
33+
</data>

report_docx/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import ir_actions_report

0 commit comments

Comments
 (0)