跳到正文
Skillpedia
网站与界面(前端)48k · #5349

odoo-qweb-templates

它能做什么

这个工具帮你为 Odoo 系统创建文档模板(例如 PDF 发票、电子邮件和网站页面)。它会生成所需代码,以有条理且动态的方式展示信息。

适用场景

  • ✓创建新的自定义 PDF 报表时。
  • ✓开发自动邮件模板时。
  • ✓在网站页面中添加动态内容时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/odoo-qweb-templates/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/odoo-qweb-templates/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“为 PDF 发票创建一个 QWeb 模板,显示客户名称和总金额。”

每周 5 个新技能,1 分钟读完。

工作原理

你描述需要的文档类型(报表、邮件或页面),工具会生成 QWeb 代码,以及 Odoo 使用该模板所需的配置。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Odoo QWeb Templates

Overview

QWeb is Odoo's primary templating engine, used for PDF reports, website pages, and email templates. This skill generates correct, well-structured QWeb XML with proper directives, translation support, and report action bindings.

When to Use This Skill

  • Creating a custom PDF report (invoice, delivery slip, certificate).
  • Building a QWeb email template triggered by workflow actions.
  • Designing Odoo website pages with dynamic content.
  • Debugging QWeb rendering errors (t-if, t-foreach issues).

How It Works

  1. Activate: Mention @odoo-qweb-templates and describe the report or template needed.
  2. Generate: Receive a complete ir.actions.report record and QWeb template.
  3. Debug: Paste a broken template to identify and fix rendering issues.

Examples

Example 1: Custom PDF Report

<!-- Report Action -->
<record id="action_report_patient_card" model="ir.actions.report">
    <field name="name">Patient Card</field>
    <field name="model">hospital.patient</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">hospital_management.report_patient_card</field>
    <field name="binding_model_id" ref="model_hospital_patient"/>
</record>

<!-- QWeb Template -->
<template id="report_patient_card">
    <t t-call="web.html_container">
        <t t-foreach="docs" t-as="doc">
            <t t-call="web.external_layout">
                <div class="page">
                    <h2>Patient Card</h2>
                    <table class="table table-bordered">
                        <tr>
                            <td><strong>Name:</strong></td>
                            <td><t t-field="doc.name"/></td>
                        </tr>
                        <tr>
                            <td><strong>Doctor:</strong></td>
                            <td><t t-field="doc.doctor_id.name"/></td>
                        </tr>
                        <tr>
                            <td><strong>Status:</strong></td>
                            <td><t t-field="doc.state"/></td>
                        </tr>
                    </table>
                </div>
            </t>
        </t>
    </t>
</template>

Example 2: Conditional Rendering

<!-- Show a warning block only if the patient is not confirmed -->
<t t-if="doc.state == 'draft'">
    <div class="alert alert-warning">
        <strong>Warning:</strong> This patient has not been confirmed yet.
    </div>
</t>

Best Practices

  • ✅ Do: Use t-field for model fields — Odoo auto-formats dates, monetary values, and booleans correctly.
  • ✅ Do: Use t-out (Odoo 15+) for safe HTML output of non-field strings. Use t-esc only on Odoo 14 and below (it HTML-escapes output).
  • ✅ Do: Call web.external_layout for PDF reports to automatically include the company header, footer, and logo.
  • ✅ Do: Use _lt() (lazy translation) for translatable string literals inside Python report helpers, not inline t-esc.
  • ❌ Don't: Use raw Python expressions inside QWeb — compute values in the model or a report _get_report_values() helper.
  • ❌ Don't: Forget t-as when using t-foreach; without it, you can't access the current record in the loop body.
  • ❌ Don't: Use t-esc where you intend to render HTML content — it will escape the tags and print them as raw text.

Limitations

  • Does not cover website controller routing for dynamic QWeb pages — that requires Python http.route knowledge.
  • Email template QWeb has different variable scope than report QWeb (object vs docs) — this skill primarily focuses on PDF reports.
  • QWeb JavaScript (used in Kanban/Form widgets) is a different engine; this skill covers server-side QWeb only.
  • Does not cover wkhtmltopdf configuration for PDF rendering issues (page size, margins, header/footer overlap).
常见问题

什么是 QWeb?

QWeb 是 Odoo 用来创建文档模板的语言,比如 PDF 报表和邮件,可以动态展示信息。

“t-if”和“t-foreach”之类的“指令”是什么?

它们是 QWeb 中用来控制内容显示方式的特殊命令。例如,t-if 只在条件成立时才显示某些内容,t-foreach 则会为列表中的每一项重复渲染一段内容。

这个能用于 Odoo 中的任何类型文档吗?

主要适用于 PDF 报表、邮件模板和网站页面。它不涵盖用于复杂网页的 Python 编程,也不涉及 PDF 打印设置。

详情

作者的原始描述

Expert in Odoo QWeb templating for PDF reports, email templates, and website pages. Covers t-if, t-foreach, t-field, and report actions.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5349
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能