| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
•
Discuss (mail)
• Website (website) |
| Lines of code | 701 |
| Technical Name |
deltatech_document_template |
| License | LGPL-3 |
| Website | https://www.terrabit.ro |
Deltatech Document Template
Generic document templates with sections and validation workflow
Overview
deltatech_document_template provides a generic, reusable engine to
define document templates and generate finalized documents from them in
Odoo 19. It is business‑agnostic and can target any model via
res_model/res_id. The module supports mixed content (manual
HTML, embedded QWeb reports, or QWeb views), a simple workflow on
generated documents, and a Print menu integration that opens or reuses a
unique generated document per template and target record.
Key Concepts
- ✓Document Template (
document.template):- Defines the target model (
res_model). - Holds an ordered list of sections (
document.template.section). - Can register a Print‑menu server action on the target model that opens a generated document (creating one if needed).
- Defines the target model (
- ✓Template Section (
document.template.section):- Defines one piece of content for a template, ordered by
sequence. - Content types (
content_type):html– manual HTML (body_html) rendered as a QWeb fragment with placeholders (e.g.,t-esc="o.display_name").report– an embedded QWeb report (report_id) rendered for the target record; sanitized before insertion to avoid nested layouts/duplicate pages.view– a QWeb template/view (view_id) rendered for the target record.
page_break_afterinserts a page break between sections when generating a document.
- Defines one piece of content for a template, ordered by
- ✓Generated Document (
document.generated):- Instantiates a template for a specific record (
res_modelvia template, andres_id). - Concatenates all sections to produce the final HTML
body, with QWeb rendering and embedded report sanitization. - Has a workflow: Draft → Generated → Validated.
- “Print PDF” action exports the current body via a dedicated QWeb PDF report and auto‑attaches the output to the target record.
- Instantiates a template for a specific record (
Main Features
- ✓Model‑agnostic: target any model by setting
res_modelon the template andres_idon the generated document. - ✓Mixed content assembly with QWeb rendering:
- Manual HTML sections (QWeb fragment with placeholders and conditionals).
- Embedded report sections (existing
ir.actions.reporton the target model), sanitized to avoid nestedexternal_layout/div.pagewrappers. - Embedded QWeb view sections by
view_id.
- ✓Page breaks between sections using
<div style="page-break-before: always;"></div>whenpage_break_afteris set (never appended after the last section). - ✓Print menu integration (server action with
binding_type = 'report'): opens an existingdocument.generatedfor the active record and template, or starts a new one if it does not exist yet. - ✓Uniqueness enforced: only one generated document per (
template_id,res_model,res_id) via a Python constraint (no_sql_constraintsin Odoo 19). - ✓Clear workflow with button visibility by state:
- Generate: visible in Draft/Generated; hidden in Validated.
- Validate: visible in Generated only.
- Reset to Draft: visible in Generated/Validated.
- Print PDF: visible in Generated/Validated.
- ✓Printing auto‑attaches the resulting PDF (or HTML fallback) to the
target
res_model/res_id. - ✓Chatter integration: when a generated document is created (or when its target is set later), a note with a link to the generated document is posted automatically on the target record’s chatter.
Models & Fields
document.templatename(Char): Optional label of the template.res_model(Char): Technical name of the target model (e.g.,res.partner).section_ids(One2many): Relateddocument.template.sectionrows.server_action_id(Many2one →ir.actions.server, readonly): Optional server action bound to the model’s Print menu to open/reuse a generated document.
document.template.sectionname(Char, required)sequence(Integer): Ordering within the template.template_id(Many2one → document.template)content_type(Selection):html|report|view(defaulthtml).body_html(Html, QWeb‑enabled): Manual content with placeholders and directives; sanitized settings keep QWeb attributes.report_id(Many2one → ir.actions.report): Forcontent_type = 'report'. Domain constrained to template’sres_modeland QWeb types.view_id(Many2one → ir.ui.view): Forcontent_type = 'view'(QWeb views/templates).page_break_after(Boolean): Insert a page break after this section (not after the last section overall).res_model(Char, related): Mirrorstemplate_id.res_modelfor editors and dynamic placeholders.- Helpers:
action_clear_report()clearsreport_id.
document.generatedname(Char, computed): “: “ or “Generated Document”.template_id(Many2one → document.template, required)res_model(Char, related & stored): From template.res_id(Many2oneReference): Target record ID, validated againstres_model.body(Html): Concatenated result built from sections.date_issued(Date): Defaults to today.state(Selection):draft,generated,validated.- Uniqueness: one row per (
template_id,res_model,res_id) enforced by a server‑side constraint. - Actions:
action_generate(): Buildbodyfrom sections with QWeb rendering and embedded report sanitization, then set state togenerated.action_validate(): Set state tovalidated.action_reset_to_draft(): Set state back todraft.action_print_pdf(): Render QWeb PDF and return action; also auto‑attach the output to the target record (res_model/res_id).
User Interface
- ✓Templates: Tree and form views to define
res_modeland manage sections inline. Button box to add/remove the Print‑menu server action. - ✓Sections: Standalone tree and form; fields shown depend on
content_type(report/view/body_html). The HTML widget is configured with code view and dynamic placeholders enabled. A “Clear Report” button resetsreport_id. - ✓Generated Documents: Tree and form with header buttons for workflow and printing. Button visibility adapts to state (see above). Body is shown for review/edit in a notebook tab.
- ✓Menus: Under Settings → Technical → Document Templates
- Templates
- Sections
- Generated Documents
Printing
- Generated documents have a dedicated QWeb PDF report
(
report_document_generated_action). The QWeb template wraps thebodywithin the standard external layout; it avoids adding extra page wrappers so embedded reports are not duplicated. - The “Print PDF” action is available in states
generatedandvalidatedand will auto‑attach the produced file to the target record. If PDF rendering is not available, an HTML attachment is stored as fallback.
Typical Workflow
- Create a
Document Templateand set itsres_model(e.g.,res.partner). Optionally register the Print‑menu action. - Add one or more
Sectionsand choose theircontent_type:html: author content with QWeb placeholders inbody_html;report: select a report to embed; the module will sanitize the HTML before insertion;view: select a QWeb view/template to render.- Enable
page_break_afterwhere you want page boundaries.
- Create a
Generated Document(either via the Print menu on a target record or manually):- Pick the template and the target
res_id(defaults are filled by the Print‑menu action). - Click
Generateto assemble content from sections. - Use
Print PDF(available fromgenerated) to review or share; the file will be attached to the target record.Validateonce finalized.
- Pick the template and the target
Compatibility
- Targeted at Odoo 19 and aligned with its UI guidelines (no legacy
attrs/statesin XML). The views use simpleinvisibleexpressions where needed. - The standalone web view for
document.generateduses the new editor stack:html_builder/html_editorassets (Odoo 19). No legacyweb_editorbundle is used.
Installation
Ensure the module path is on your
addons_path(this repository already configures custom paths in the provided.conf).Install the module:
./odoo/odoo-bin -c odoo18.conf -d o19_dev -i deltatech_document_template --stop-after-init
- Running Tests
The module ships with SavepointCase tests that cover: QWeb rendering for manual HTML, report/view sections, sanitization/page breaks, uniqueness constraint, Print‑menu server action (open existing vs create new), and printing with auto‑attachment.
Run tests in a disposable database:
./odoo/odoo-bin -c odoo18.conf -d o19_test -u deltatech_document_template --test-tags=deltatech_document_template --stop-after-init
Security
- Basic ACLs allow internal users (
base.group_user) to create, read, update, and delete templates, sections, and generated documents.
Known Limitations & Notes
- ✓Reports defined strictly for PDF may not provide HTML rendering for
embedding; the section falls back to its manual
body_htmlwhen this occurs. - ✓The sanitizer removes common layout wrappers (e.g.,
web.external_layout,web.html_container,div.page) from embedded reports and keeps the inner page content to avoid duplication when printing the final PDF. - ✓The generated HTML
bodyis printed through a dedicated QWeb PDF wrapper; ensure your PDF stack (wkhtmltopdf or Qt‑WebEngine based) handles page breaks and CSS as expected.
Bug Tracker
Bugs are tracked on Terrabit Issues. In case of trouble, please check there if your issue has already been reported.
Do not contact contributors directly about support or help with technical issues.
Credits
Authors
- Deltatech
Maintainers
This module is part of the terrabit-solutions/bitshop project on GitHub.
You are welcome to contribute.
Need help getting started?
We are an Odoo partner building apps for the Romanian market (SAGA & WinMentor export; Romanian accounting localization in progress). Direct support from the team that built the module.
Contact Terrabit →
Please log in to comment on this module