Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 250 additions & 0 deletions report_qweb_text_control/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
=================
QWeb Text Control
=================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:620ee9b73c86f1ddea10c06a761f12e08bce6e56c2963c2bed1a99be1f88df0b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/14.0/report_qweb_text_control
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_qweb_text_control
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Allow text reports to generate positional text files by providing
precise control over whitespace, special characters, and field formatting.

Use Case
--------

Generate fixed-width text files for legacy systems, bank transfers, or any interface
requiring exact positional formatting with specific characters and spacing.

Example
-------

Template::

<span t-esc="A(partner.name, 20)"/>
<span t-esc="N(partner.id, 10)"/>
<span t-esc="M(partner.credit_limit, 12)"/>

Output::

John Doe 00000012340000015000+

**Table of contents**

.. contents::
:local:

Configuration
=============

Default Replacement Elements
-----------------------------

The module provides these default replacement elements:

* ``<CR>`` → Carriage return (``\r``)
* ``<LF>`` → Line feed (``\n``)
* ``<CRLF>`` → Windows line ending (``\r\n``)
* ``<TAB>`` → Tab character (``\t``)
* ``<SEMICOLON>`` → Semicolon (``;``)
* ``<SPAN>`` → Removed (empty string)
* ``<DIV>`` → Removed (empty string)

Field Formatting Functions
--------------------------

The module includes these field formatting functions:

* ``A(value, length=None)`` - Alphanumeric: left-aligned, space-padded
* ``N(value, length=None, digits=None, sign=False)`` - Numeric: right-aligned,
zero-padded, optional sign at the end
* ``M(value, length=None)`` - Monetary: calls ``N`` with ``digits=2`` and ``sign=True``
* ``T(value, length=None, digits=2)`` - Tax: calls ``N`` with ``digits=2`` and ``sign=False``
* ``D(value, length=8, dtformat="%Y%m%d")`` - Date: formats dates with
customizable format, defaults to yyyymmdd
* ``H(value, length=4, dtformat="%H%M")`` - Time: formats times with
customizable format, defaults to hhmm
* ``DT(value, length=12, dtformat="%Y%m%d%H%M")`` - Datetime: formats
datetime with customizable format, defaults to yyyyMMddhhmm

Post-processing Behavior
------------------------

The module automatically performs the following post-processing on text
content:

1. Strips whitespace from each line
2. Removes all line breaks from QWeb template structure
3. Removes HTML elements (SPAN, DIV) completely
4. Replaces special elements with their defined characters
5. Returns single-line output with controlled formatting

This ensures clean, consistent text output regardless of QWeb template
formatting or HTML elements.

Usage
=====

To create a text-controlled QWeb report, define a report with
``report_type="qweb-text"`` and enable the "Enable Text Control" option:

.. code-block:: xml

<record id="action_report_custom_text" model="ir.actions.report">
<field name="name">Custom Text Report</field>
<field name="model">your.model</field>
<field name="report_type">qweb-text</field>
<field name="text_control_enabled" eval="True"/>
<field name="report_name">your_module.report_custom_text</field>
<field name="binding_model_id" ref="model_your_model"/>
<field name="binding_type">report</field>
</record>

Special Elements in Templates
------------------------------

In your QWeb template, use special elements for controlled output. HTML elements
like SPAN and DIV are automatically removed:

.. code-block:: xml

<template id="report_custom_text">
<t t-foreach="docs" t-as="doc">
<span t-esc="doc.name"/>,<span t-esc="doc.email"/><LF/>
<span t-esc="doc.phone"/>,<span t-esc="doc.address"/><CRLF/>
<span t-esc="doc.field1"/><TAB/><span t-esc="doc.field2"/><SEMICOLON/><span t-esc="doc.field3"/>
</t>
</template>

Field Formatting
-----------------

The module provides field formatting functions available in templates:

.. code-block:: xml

<!-- Alphanumeric (A): left-aligned, space-padded -->
<span t-esc="A(doc.name, 10)"/>

<!-- Numeric (N): right-aligned, zero-padded -->
<span t-esc="N(doc.amount, 8)"/>

<!-- Numeric with decimals and sign (sign at the end) -->
<span t-esc="N(doc.amount, 12, digits=2, sign=True)"/>

<!-- Monetary (M): calls N with digits=2 and sign=True -->
<span t-esc="M(doc.total, 12)"/>

<!-- Date (D): formats dates, defaults to yyyymmdd -->
<span t-esc="D(doc.date)"/>

<!-- Date with custom format -->
<span t-esc="D(doc.date, dtformat='%Y-%m-%d')"/>

<!-- Date with length padding -->
<span t-esc="D(doc.date, 12, dtformat='%Y%m%d')"/>

<!-- Time (T): formats times, defaults to hhmm -->
<span t-esc="T(doc.time)"/>

<!-- Time with custom format -->
<span t-esc="T(doc.time, dtformat='%H:%M')"/>

<!-- Time with length padding -->
<span t-esc="T(doc.time, 6, dtformat='%H:%M:%S')"/>

<!-- Datetime (DT): formats datetime, defaults to yyyyMMddhhmm -->
<span t-esc="DT(doc.datetime)"/>

<!-- Datetime with custom format -->
<span t-esc="DT(doc.datetime, dtformat='%Y-%m-%d %H:%M')"/>

<!-- Datetime with length padding -->
<span t-esc="DT(doc.datetime, 20, dtformat='%Y-%m-%d %H:%M:%S')"/>

Customization
-------------

Override the ``_get_replacement_elements()`` method to define your own special
elements:

.. code-block:: python

from odoo import models

class CustomTextReport(models.Model):
_inherit = "ir.actions.report"

def _get_replacement_elements(self):
"""Override to customize replacement elements"""
elements = super()._get_replacement_elements()
elements.update({
"CUSTOM": "CustomValue",
"NEWLINE": "\r\n",
})
return elements

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_text_control%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Open Source Integrators

Contributors
~~~~~~~~~~~~

This module was developed with AI assistance under close guidance and supervision
from experienced Odoo developers. The development utilized Cascade (SWE-1.5) for
code implementation and testing, with Claude AI providing architectural guidance
and code quality review. All AI-generated code was thoroughly reviewed, validated,
and approved by human supervisors.

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/report_qweb_text_control>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions report_qweb_text_control/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2025 Open Source Integrators
from . import report
22 changes: 22 additions & 0 deletions report_qweb_text_control/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2025 Open Source Integrators
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "QWeb Text Control",
"summary": "Controls whitespace and special characters in text QWeb reports",
"version": "14.0.1.0.0",
"category": "Reporting",
"website": "https://github.com/OCA/reporting-engine",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"base",
],
"data": [
"views/ir_actions_report_views.xml",
],
"demo": [
"demo/partner_report.xml",
],
}
30 changes: 30 additions & 0 deletions report_qweb_text_control/demo/partner_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<!-- Demo Text Report for Partners -->
<record id="action_report_partner_text" model="ir.actions.report">
<field name="name">Partner Text Report</field>
<field name="model">res.partner</field>
<field name="report_type">qweb-text</field>
<field name="text_control_enabled" eval="True" />
<field
name="report_name"
>report_qweb_text_control.report_partner_text</field>
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="binding_type">report</field>
</record>

<!-- QWeb Template for Partner Text Report -->
<template id="report_partner_text">
<t t-foreach="docs" t-as="partner">
<span t-esc="A(partner.name, 40)" />
<span t-esc="A(partner.email, 30)" />
<span t-esc="A(partner.phone, 20)" />
<span t-esc="A(partner.country_id.name, 20)" />
<span t-esc="M(partner.company_type == 'company' and 100 or 0, 8)" />
<span t-esc="M(partner.credit_limit, 12)" />
<CRLF />
</t>
</template>
</data>
</odoo>
44 changes: 44 additions & 0 deletions report_qweb_text_control/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Default Replacement Elements
-----------------------------

The module provides these default replacement elements:

* ``<CR>`` → Carriage return (``\r``)
* ``<LF>`` → Line feed (``\n``)
* ``<CRLF>`` → Windows line ending (``\r\n``)
* ``<TAB>`` → Tab character (``\t``)
* ``<SEMICOLON>`` → Semicolon (``;``)
* ``<SPAN>`` → Removed (empty string)
* ``<DIV>`` → Removed (empty string)

Field Formatting Functions
--------------------------

The module includes these field formatting functions:

* ``A(value, length=None)`` - Alphanumeric: left-aligned, space-padded
* ``N(value, length=None, digits=None, sign=False)`` - Numeric: right-aligned,
zero-padded, optional sign at the end
* ``M(value, length=None)`` - Monetary: calls ``N`` with ``digits=2`` and ``sign=True``
* ``T(value, length=None, digits=2)`` - Tax: calls ``N`` with ``digits=2`` and ``sign=False``
* ``D(value, length=8, dtformat="%Y%m%d")`` - Date: formats dates with
customizable format, defaults to yyyymmdd
* ``H(value, length=4, dtformat="%H%M")`` - Time: formats times with
customizable format, defaults to hhmm
* ``DT(value, length=12, dtformat="%Y%m%d%H%M")`` - Datetime: formats
datetime with customizable format, defaults to yyyyMMddhhmm

Post-processing Behavior
------------------------

The module automatically performs the following post-processing on text
content:

1. Strips whitespace from each line
2. Removes all line breaks from QWeb template structure
3. Removes HTML elements (SPAN, DIV) completely
4. Replaces special elements with their defined characters
5. Returns single-line output with controlled formatting

This ensures clean, consistent text output regardless of QWeb template
formatting or HTML elements.
5 changes: 5 additions & 0 deletions report_qweb_text_control/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module was developed with AI assistance under close guidance and supervision
from experienced Odoo developers. The development utilized Cascade (SWE-1.5) for
code implementation and testing, with Claude AI providing architectural guidance
and code quality review. All AI-generated code was thoroughly reviewed, validated,
and approved by human supervisors.
21 changes: 21 additions & 0 deletions report_qweb_text_control/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Allow text reports to generate positional text files by providing
precise control over whitespace, special characters, and field formatting.

Use Case
--------

Generate fixed-width text files for legacy systems, bank transfers, or any interface
requiring exact positional formatting with specific characters and spacing.

Example
-------

Template::

<span t-esc="A(partner.name, 20)"/>
<span t-esc="N(partner.id, 10)"/>
<span t-esc="M(partner.credit_limit, 12)"/>

Output::

John Doe 00000012340000015000+
Loading
Loading