Skip to content

unclecatvn/agent-skills / skills/odoo-19.0

odoo-19

Verified

Odoo 19 development knowledge base with 18 specialized guides covering Actions (ir.actions.*, cron jobs, server actions), Controllers (HTTP routing, endpoints, auth types), Data files (XML/CSV records, shortcuts, noupdate), API Decorators (@api.depends, @api.constrains, @api.ondelete, @api.onchange, @api.model, @api.private), SQL Constraints (models.Constraint replacing _sql_constraints), Database Indexes (models.Index), Module development (manifest, wizards, reports), Field types (Char, Text, Monetary, relational fields), Manifest configuration (__manifest__.py, dependencies, asset bundles), Mixins (mail.thread, mail.activity.mixin, mail.alias.mixin, utm.mixin), ORM Model methods (search, CRUD, domain filters, recordsets, CamelCase model naming), Migration scripts (pre/post/end hooks, data migration), OWL frontend components (hooks, services, lifecycle), Performance optimization (N+1 prevention, batch ops, _read_group), QWeb Reports (PDF/HTML, paper formats, barcodes, t-out), Security/ACL (record rules, field permissions, privilege-based groups, @api.private), Testing (TransactionCase, HttpCase, mocking, query count assertions), Transactions (savepoints, UniqueViolation, serialization failures), Translations (i18n, PO files, translatable fields), XML Views (list/form/search, kanban card templates, xpath inheritance, QWeb templates). Use when writing, reviewing, or debugging any Odoo 19 Python or XML code, creating or modifying modules, fixing performance issues, or looking up Odoo 19 API patterns and best practices. Includes CSS/SCSS asset authoring and review for Odoo addons.

references/odoo-19-reports-guide.md

View on GitHub
# Odoo 19 Reports Guide

## Coding Conventions

Use focused report/template filenames and stable descriptive XML IDs.

Guide for creating QWeb reports in Odoo 19: PDF/HTML reports, templates, and paper formats.

## Table of Contents

- [Report Basics](#report-basics)
- [Report Declaration](#report-declaration)
- [Report Templates](#report-templates)
- [Custom Reports](#custom-reports)
- [Paper Formats](#paper-formats)
- [Translatable Reports](#translatable-reports)
- [Barcodes](#barcodes)

---

## Report Basics

Reports are written in HTML/QWeb. PDF rendering is performed by wkhtmltopdf.

Reports consist of:

1. A **report action** (`ir.actions.report`)
2. A **QWeb template** for the report content

---

## Report Declaration

### No `<report>` Shortcut

Odoo 19 has no `<report>` tag (the XML loader only accepts `record`, `template`,
`menuitem`, `function`, `delete` and `asset`); a `<report .../>` element fails validation.
Always declare an `ir.actions.report` record.

### Using record Tag

```xml
<record id="my_report" model="ir.actions.report">
    <field name="name">My Report</field>
    <field name="model">my.model</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">my_module.my_template</field>
    <field name="print_report_name">'My Report - %s' % (object.name)</field>
    <field name="binding_model_id" ref="model_my_model"/>
    <field name="paperformat_id" ref="base.paperformat_euro"/>
</record>
```

### Report Attributes

| Attribute           | Description                               |
| ------------------- | ----------------------------------------- |
| `id`                | External identifier of the record         |
| `name`              | Report name                               |
| `model`             | Model for the report                      |
| `report_type`       | `qweb-pdf` or `qweb-html`                 |
| `report_name`       | External ID of QWeb template              |
| `report_file`       | Path of the main report file              |
| `print_report_name` | Python expression for filename            |
| `paperformat_id`    | Paper format                              |
| `binding_model_id`  | Model to show in Print menu               |
| `group_ids`         | Groups allowed to use report              |
| `multi`             | If True, don't show on form view          |
| `attachment_use`    | Generate once, reprint from stored        |
| `attachment`        | Python expression for attachment          |

---

## Report Templates

### Template Variables

Report templates always have access to:

| Variable            | Description                                   |
| ------------------- | --------------------------------------------- |
| `docs`              | Records for the current report                |
| `doc_ids`           | List of ids for `docs`                        |
| `doc_model`         | Model name for `docs`                         |
| `time`              | Python `time` module                          |
| `user`              | User printing the report                      |
| `res_company`       | Current user's company                        |
| `website`           | Current website (if any)                      |
| `web_base_url`      | Base URL for webserver                        |
| `context_timestamp` | Function to convert datetime to user timezone |

### Minimal Template

```xml
<template id="report_invoice">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="web.external_layout">
                <div class="page">
                    <h2>Invoice</h2>
                    <p>Customer: <span t-field="o.partner_id.name"/></p>
                    <p>Total: <span t-field="o.amount_total"/></p>
                </div>
            </t>
        </t>
    </t>
</template>
```

### External Layout

Calling `web.external_layout` adds default header and footer.

```xml
<t t-call="web.external_layout">
    <div class="page">
        <!-- Your content here -->
    </div>
</t>
```

#### Layout Variants

| Layout                           | Description                          |
| -------------------------------- | ------------------------------------ |
| `web.external_layout`            | Standard layout (with header/footer) |
| `web.external_layout_background` | With background                      |
| `web.external_layout_clean`      | Clean layout (minimal)               |
| `web.external_layout_boxed`      | Boxed layout                         |

---

## Custom Reports

For custom reports, create a report class that overrides `_get_report_values`:

```python
from odoo import models

class MyReport(models.AbstractModel):
    _name = 'report.my_module.my_template'
    _description = 'My Custom Report'

    def _get_report_values(self, docids, data=None):
        docs = self.env['my.model'].browse(docids)

        return {
            'doc_ids': docids,
            'doc_model': 'my.model',
            'docs': docs,
            'data': data,
            'my_custom_value': self._compute_custom(docs),
        }

    def _compute_custom(self, docs):
        # Custom computation
        return sum(doc.amount for doc in docs)
```

Use custom values in template:

```xml
<template id="my_template">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="o">
            <t t-call="web.external_layout">
                <div class="page">
                    <h2>My Report</h2>
                    <p>Total: <span t-out="my_custom_value"/></p>
                </div>
            </t>
        </t>
    </t>
</template>
```

---

## Paper Formats

### Built-in Paper Formats

| Format                  | Size   |
| ----------------------- | ------ |
| `base.paperformat_euro` | A4     |
| `base.paperformat_us`   | Letter |

For another size (e.g. `Legal`), define a `report.paperformat` record with that `format`.

### Custom Paper Format

```xml
<record id="paperformat_my_format" model="report.paperformat">
    <field name="name">My Custom Format</field>
    <field name="default" eval="True"/>
    <field name="format">A4</field>
    <field name="page_height">297</field>
    <field name="page_width">210</field>
    <field name="orientation">Portrait</field>
    <field name="margin_top">40</field>
    <field name="margin_bottom">20</field>
    <field name="margin_left">7</field>
    <field name="margin_right">7</field>
    <field name="header_line" eval="False"/>
    <field name="header_spacing">35</field>
    <field name="dpi">90</field>
</record>
```

### Format Attributes

| Attribute        | Description                             |
| ---------------- | --------------------------------------- |
| `format`         | Paper size (A4, Letter, etc.) or Custom |
| `page_height`    | Page height in mm                       |
| `page_width`     | Page width in mm                        |
| `orientation`    | Portrait or Landscape                   |
| `margin_top`     | Top margin in mm                        |
| `margin_bottom`  | Bottom margin in mm                     |
| `margin_left`    | Left margin in mm                       |
| `margin_right`   | Right margin in mm                      |
| `header_line`    | Show header line                        |
| `header_spacing` | Header spacing in mm                    |
| `dpi`            | Resolution (default: 90)                |

---

## Translatable Reports

### Two-Template Approach

1. Main template (wrapper)
2. Translatable document template

```xml
<!-- Main template -->
<template id="report_saleorder">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="doc">
            <t t-call="sale.report_saleorder_document" t-lang="doc.partner_id.lang"/>
        </t>
    </t>
</template>

<!-- Translatable template -->
<template id="report_saleorder_document">
    <!-- Re-browse with partner language -->
    <t t-set="doc" t-value="doc.with_context(lang=doc.partner_id.lang)" />
    <t t-call="web.external_layout">
        <div class="page">
            <div class="row">
                <div class="col-6">
                    <strong>Invoice address:</strong>
                    <div t-field="doc.partner_invoice_id" t-options='{"widget": "contact", "no_marker": True}'/>
                </div>
            </div>
        </div>
    </t>
</template>
```

### Language Attribute

Use `t-lang` to set language for a template section:

```xml
<t t-call="my.template" t-lang="fr_FR">
    <!-- Will be rendered in French -->
</t>

<t t-call="my.template" t-lang="doc.partner_id.lang">
    <!-- Will be rendered in partner's language -->
</t>
```

**Note**: Works only with `t-call`, not on regular XML nodes.

---

## Barcodes

### Embed Barcode

```xml
<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', o.name, 200, 200)"/>
```

### Barcode Controller Parameters

| Parameter       | Values                                           |
| --------------- | ------------------------------------------------ |
| `type`          | `QR`, `Code128`, `EAN13`, `EAN8`, `UPCA`, `UPCE` |
| `value`         | Barcode value                                    |
| `width`         | Width in pixels                                  |
| `height`        | Height in pixels                                 |
| `humanreadable` | `1` or `0` (show text below)                     |

### Example

```xml
<div class="page">
    <h2>Product: <span t-field="o.name"/></h2>
    <img
        t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;humanreadable=1' % ('EAN13', o.barcode, 600, 100)"
        alt="Barcode"/>
</div>
```

---

## QWeb Tips

### Directives

| Directive   | Description                                           |
| ----------- | ----------------------------------------------------- |
| `t-out`     | Escape and output value (replaces deprecated `t-esc`) |
| `t-field`   | Output field value (formatted)                        |
| `t-if`      | Conditional display                                   |
| `t-elif`    | Else if condition                                     |
| `t-else`    | Else condition                                        |
| `t-foreach` | Loop over collection                                  |
| `t-as`      | Variable name for foreach                             |
| `t-set`     | Set variable                                          |
| `t-call`    | Call another template                                 |
| `t-lang`    | Set language for template                             |

### t-field Options

```xml
<span t-field="o.date" t-options='{"widget": "date"}'/>
<span t-field="o.amount" t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
<div t-field="o.partner_id" t-options='{"widget": "contact", "no_marker": True}'/>
```

---

## References

- Source: Odoo 19 documentation `/doc/developer/reference/backend/reports.rst`
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall