|
| 1 | +================= |
| 2 | +QWeb Text Control |
| 3 | +================= |
| 4 | + |
| 5 | +.. |
| 6 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 7 | + !! This file is generated by oca-gen-addon-readme !! |
| 8 | + !! changes will be overwritten. !! |
| 9 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 10 | + !! source digest: sha256:620ee9b73c86f1ddea10c06a761f12e08bce6e56c2963c2bed1a99be1f88df0b |
| 11 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 12 | +
|
| 13 | +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png |
| 14 | + :target: https://odoo-community.org/page/development-status |
| 15 | + :alt: Beta |
| 16 | +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png |
| 17 | + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html |
| 18 | + :alt: License: LGPL-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/14.0/report_qweb_text_control |
| 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-14-0/reporting-engine-14-0-report_qweb_text_control |
| 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=14.0 |
| 27 | + :alt: Try me on Runboat |
| 28 | + |
| 29 | +|badge1| |badge2| |badge3| |badge4| |badge5| |
| 30 | + |
| 31 | +Allow text reports to generate positional text files by providing |
| 32 | +precise control over whitespace, special characters, and field formatting. |
| 33 | + |
| 34 | +Use Case |
| 35 | +-------- |
| 36 | + |
| 37 | +Generate fixed-width text files for legacy systems, bank transfers, or any interface |
| 38 | +requiring exact positional formatting with specific characters and spacing. |
| 39 | + |
| 40 | +Example |
| 41 | +------- |
| 42 | + |
| 43 | +Template:: |
| 44 | + |
| 45 | + <span t-esc="A(partner.name, 20)"/><PIPE/> |
| 46 | + <span t-esc="N(partner.id, 10)"/><PIPE/> |
| 47 | + <span t-esc="M(partner.credit_limit, 12)"/> |
| 48 | + |
| 49 | +Output:: |
| 50 | + |
| 51 | + John Doe |0000001234|0000015000+ |
| 52 | + |
| 53 | +**Table of contents** |
| 54 | + |
| 55 | +.. contents:: |
| 56 | + :local: |
| 57 | + |
| 58 | +Configuration |
| 59 | +============= |
| 60 | + |
| 61 | +Default Replacement Elements |
| 62 | +----------------------------- |
| 63 | + |
| 64 | +The module provides these default replacement elements: |
| 65 | + |
| 66 | +* ``<CR>`` → Carriage return (``\r``) |
| 67 | +* ``<LF>`` → Line feed (``\n``) |
| 68 | +* ``<CRLF>`` → Windows line ending (``\r\n``) |
| 69 | +* ``<TAB>`` → Tab character (``\t``) |
| 70 | +* ``<SEMICOLON>`` → Semicolon (``;``) |
| 71 | +* ``<SPAN>`` → Removed (empty string) |
| 72 | +* ``<DIV>`` → Removed (empty string) |
| 73 | + |
| 74 | +Field Formatting Functions |
| 75 | +-------------------------- |
| 76 | + |
| 77 | +The module includes these field formatting functions: |
| 78 | + |
| 79 | +* ``A(value, length=None)`` - Alphanumeric: left-aligned, space-padded |
| 80 | +* ``N(value, length=None, digits=None, sign=False)`` - Numeric: right-aligned, |
| 81 | + zero-padded, optional sign at the end |
| 82 | +* ``M(value, length=None)`` - Monetary: calls ``N`` with ``digits=2`` and ``sign=True`` |
| 83 | +* ``T(value, length=None, digits=2)`` - Tax: calls ``N`` with ``digits=2`` and ``sign=False`` |
| 84 | +* ``D(value, length=8, dtformat="%Y%m%d")`` - Date: formats dates with |
| 85 | + customizable format, defaults to yyyymmdd |
| 86 | +* ``H(value, length=4, dtformat="%H%M")`` - Time: formats times with |
| 87 | + customizable format, defaults to hhmm |
| 88 | +* ``DT(value, length=12, dtformat="%Y%m%d%H%M")`` - Datetime: formats |
| 89 | + datetime with customizable format, defaults to yyyyMMddhhmm |
| 90 | + |
| 91 | +Post-processing Behavior |
| 92 | +------------------------ |
| 93 | + |
| 94 | +The module automatically performs the following post-processing on text |
| 95 | +content: |
| 96 | + |
| 97 | +1. Strips whitespace from each line |
| 98 | +2. Removes all line breaks from QWeb template structure |
| 99 | +3. Removes HTML elements (SPAN, DIV) completely |
| 100 | +4. Replaces special elements with their defined characters |
| 101 | +5. Returns single-line output with controlled formatting |
| 102 | + |
| 103 | +This ensures clean, consistent text output regardless of QWeb template |
| 104 | +formatting or HTML elements. |
| 105 | + |
| 106 | +Usage |
| 107 | +===== |
| 108 | + |
| 109 | +To create a text-controlled QWeb report, define a report with |
| 110 | +``report_type="qweb-text"`` and enable the "Enable Text Control" option: |
| 111 | + |
| 112 | +.. code-block:: xml |
| 113 | +
|
| 114 | + <record id="action_report_custom_text" model="ir.actions.report"> |
| 115 | + <field name="name">Custom Text Report</field> |
| 116 | + <field name="model">your.model</field> |
| 117 | + <field name="report_type">qweb-text</field> |
| 118 | + <field name="text_control_enabled" eval="True"/> |
| 119 | + <field name="report_name">your_module.report_custom_text</field> |
| 120 | + <field name="binding_model_id" ref="model_your_model"/> |
| 121 | + <field name="binding_type">report</field> |
| 122 | + </record> |
| 123 | +
|
| 124 | +Special Elements in Templates |
| 125 | +------------------------------ |
| 126 | + |
| 127 | +In your QWeb template, use special elements for controlled output. HTML elements |
| 128 | +like SPAN and DIV are automatically removed: |
| 129 | + |
| 130 | +.. code-block:: xml |
| 131 | +
|
| 132 | + <template id="report_custom_text"> |
| 133 | + <t t-foreach="docs" t-as="doc"> |
| 134 | + <span t-esc="doc.name"/>,<span t-esc="doc.email"/><LF/> |
| 135 | + <span t-esc="doc.phone"/>,<span t-esc="doc.address"/><CRLF/> |
| 136 | + <span t-esc="doc.field1"/><TAB/><span t-esc="doc.field2"/><SEMICOLON/><span t-esc="doc.field3"/> |
| 137 | + </t> |
| 138 | + </template> |
| 139 | +
|
| 140 | +Field Formatting |
| 141 | +----------------- |
| 142 | + |
| 143 | +The module provides field formatting functions available in templates: |
| 144 | + |
| 145 | +.. code-block:: xml |
| 146 | +
|
| 147 | + <!-- Alphanumeric (A): left-aligned, space-padded --> |
| 148 | + <span t-esc="A(doc.name, 10)"/> |
| 149 | +
|
| 150 | + <!-- Numeric (N): right-aligned, zero-padded --> |
| 151 | + <span t-esc="N(doc.amount, 8)"/> |
| 152 | +
|
| 153 | + <!-- Numeric with decimals and sign (sign at the end) --> |
| 154 | + <span t-esc="N(doc.amount, 12, digits=2, sign=True)"/> |
| 155 | +
|
| 156 | + <!-- Monetary (M): calls N with digits=2 and sign=True --> |
| 157 | + <span t-esc="M(doc.total, 12)"/> |
| 158 | +
|
| 159 | + <!-- Date (D): formats dates, defaults to yyyymmdd --> |
| 160 | + <span t-esc="D(doc.date)"/> |
| 161 | +
|
| 162 | + <!-- Date with custom format --> |
| 163 | + <span t-esc="D(doc.date, dtformat='%Y-%m-%d')"/> |
| 164 | +
|
| 165 | + <!-- Date with length padding --> |
| 166 | + <span t-esc="D(doc.date, 12, dtformat='%Y%m%d')"/> |
| 167 | +
|
| 168 | + <!-- Time (T): formats times, defaults to hhmm --> |
| 169 | + <span t-esc="T(doc.time)"/> |
| 170 | +
|
| 171 | + <!-- Time with custom format --> |
| 172 | + <span t-esc="T(doc.time, dtformat='%H:%M')"/> |
| 173 | +
|
| 174 | + <!-- Time with length padding --> |
| 175 | + <span t-esc="T(doc.time, 6, dtformat='%H:%M:%S')"/> |
| 176 | +
|
| 177 | + <!-- Datetime (DT): formats datetime, defaults to yyyyMMddhhmm --> |
| 178 | + <span t-esc="DT(doc.datetime)"/> |
| 179 | +
|
| 180 | + <!-- Datetime with custom format --> |
| 181 | + <span t-esc="DT(doc.datetime, dtformat='%Y-%m-%d %H:%M')"/> |
| 182 | +
|
| 183 | + <!-- Datetime with length padding --> |
| 184 | + <span t-esc="DT(doc.datetime, 20, dtformat='%Y-%m-%d %H:%M:%S')"/> |
| 185 | +
|
| 186 | +Customization |
| 187 | +------------- |
| 188 | + |
| 189 | +Override the ``_get_replacement_elements()`` method to define your own special |
| 190 | +elements: |
| 191 | + |
| 192 | +.. code-block:: python |
| 193 | +
|
| 194 | + from odoo import models |
| 195 | +
|
| 196 | + class CustomTextReport(models.Model): |
| 197 | + _inherit = "ir.actions.report" |
| 198 | + |
| 199 | + def _get_replacement_elements(self): |
| 200 | + """Override to customize replacement elements""" |
| 201 | + elements = super()._get_replacement_elements() |
| 202 | + elements.update({ |
| 203 | + "CUSTOM": "CustomValue", |
| 204 | + "NEWLINE": "\r\n", |
| 205 | + }) |
| 206 | + return elements |
| 207 | +
|
| 208 | +Bug Tracker |
| 209 | +=========== |
| 210 | + |
| 211 | +Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_. |
| 212 | +In case of trouble, please check there if your issue has already been reported. |
| 213 | +If you spotted it first, help us to smash it by providing a detailed and welcomed |
| 214 | +`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**>`_. |
| 215 | + |
| 216 | +Do not contact contributors directly about support or help with technical issues. |
| 217 | + |
| 218 | +Credits |
| 219 | +======= |
| 220 | + |
| 221 | +Authors |
| 222 | +~~~~~~~ |
| 223 | + |
| 224 | +* Open Source Integrators |
| 225 | + |
| 226 | +Contributors |
| 227 | +~~~~~~~~~~~~ |
| 228 | + |
| 229 | +This module was developed with AI assistance under close guidance and supervision |
| 230 | +from experienced Odoo developers. The development utilized Cascade (SWE-1.5) for |
| 231 | +code implementation and testing, with Claude AI providing architectural guidance |
| 232 | +and code quality review. All AI-generated code was thoroughly reviewed, validated, |
| 233 | +and approved by human supervisors. |
| 234 | + |
| 235 | +Maintainers |
| 236 | +~~~~~~~~~~~ |
| 237 | + |
| 238 | +This module is maintained by the OCA. |
| 239 | + |
| 240 | +.. image:: https://odoo-community.org/logo.png |
| 241 | + :alt: Odoo Community Association |
| 242 | + :target: https://odoo-community.org |
| 243 | + |
| 244 | +OCA, or the Odoo Community Association, is a nonprofit organization whose |
| 245 | +mission is to support the collaborative development of Odoo features and |
| 246 | +promote its widespread use. |
| 247 | + |
| 248 | +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. |
| 249 | + |
| 250 | +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
0 commit comments