PDF报告¶
With Studio, you can edit existing PDF reports (e.g., invoices, quotations, etc.) or create new ones.
預設版面設計¶
The default layout of reports is managed outside Studio. Go to Companies section of the main page, click Configure Document Layout. Layout settings are company-specific but apply to all reports.
, then, in the小訣竅
在 配置文档布局`窗口右侧的报告预览中,您可以看到不同设置对报告布局的影响。创建或编辑报告时,点击屏幕左侧的 :guilabel:`打印预览 可以预览报告。
使用以下设置:
Layout: 有七种布局可供选择:
Background: The following backgrounds are available:
Blank: Nothing is displayed.
Demo logo: A demo logo is displayed in the background.
Custom: Upload a custom background image.
Text: Eight fonts are available: Lato, Roboto, Open Sans, Montserrat, Oswald, Raleway, Tajawal (which supports Arabic and Latin scripts), and Fira Mono. Go to the Google Fonts website to preview them.
Company logo: Click the Edit button to upload or change the logo. This adds the logo to the company’s record on the Company model, which you can access by going to and then clicking Update Info in the Companies section.
Colors: Change the primary and secondary colors used to structure reports. The default colors are automatically generated based on the colors of the logo.
Address: The company name and address are displayed in the header of external reports. You can add multiple lines of text.
Tagline: This is displayed in the header of external reports using the Light, Striped, Bubble, Wave and Folder layouts and in the footer of external reports using the Boxed and Bold layouts. You can add multiple lines of text.
Paper format: This defines the default paper size of reports. You can select A4 (21 cm x 29.7 cm) and US Letter (21.59 cm x 27.54 cm). This can also be defined for individual reports in the Paper format field in Studio.
備註
Other paper formats may be available depending on which apps or modules you have installed, for example, label sheets for the Inventory app or event badges for the Events app.
Creating new PDF reports¶
To create a new report for a model, (e.g., sales orders) access the model, click the (Toggle Studio) button, then click Reports. Click New and, in the popup window that opens, select the type of report. This is solely used to determine what is displayed in the header and footer:
创建报告后,您就可以开始 对其进行编辑。
编辑 PDF 报告¶
要访问某个模型可用的报告,请先访问该模型,点击 icon:oi-studio
(切换Studio)按钮,然后点击:guilabel:`报告。选择一个现有报告将其打开。
或者,您也可以打开 Studio,点击 报告,然后搜索特定报告或模型。
重要
强烈建议您**复制**标准报告,并在副本中进行修改。要复制报告,请将鼠标指针悬停在报告的右上角,点击 (垂直省略号)图标,然后选择 复制。

選項¶
选择或创建报告后,您可以使用屏幕左侧的选项:
报告编辑器¶
报告编辑器允许您修改报告的内容和格式。
小訣竅
您可以使用 撤销`或 :guilabel:`重做`按钮,或使用快捷键`CTRL +
Z
和CTRL
+Y
,来撤销或重做更改。当您离开报告时,更改会自动保存;您也可以使用 保存 按钮手动保存。
您可以通过点击屏幕左侧的 :guilabel:`重置报告`按钮,将报告重置为其标准版本。
重要
编辑报告的页眉和页脚会影响所有的标准报告和自定义报告。
条件区块¶
虚线矩形代表**条件区块**(if/else 语句)。它们用于根据特定条件来显示或隐藏内容。点击区块即可查看条件。

选择一个值以预览其对应的输出,并在必要时进行编辑。

備註
条件只能在 XML 中进行编辑。
其他内容¶
报告中有两种文本内容:
Static text, i.e., the text that is not highlighted in blue, which can be modified directly in the editor.
Dynamic text, i.e., the text that is highlighted in blue, which is replaced by field values when the report is generated, e.g., the sales order number or the quotation date.
You can add content (e.g., fields, lists, tables, images, banners, etc.) to the report using
commands. Type /
to open the powerbox, then type the
command’s name or select it from the list.
要在报告中添加静态文本,请在需要的位置键入文本。
要进行更高级的更改,您可以 直接在 XML 中编辑报告。
添加一个字段¶
To add a field, type /
and select the Field command. In the list that opens, select
or search for the field; click the right arrow next to the field name to access the list of related
fields if needed. Then, specify the default value that will be shown if the field is not completed
in the record and press Enter
.

Add or edit a table¶
There are two types of tables in reports:
Static tables, which are used to display static text or fields. For this type of table, you define the number of columns and rows when adding the table.
Dynamic tables, which are used to display data from relational fields. For this type of table, you only define the number of columns when adding the table. The number of rows in the generated report will be determined by the number of records in the related model that are linked with the current model.
Example
In a sales order report, a dynamic table is used to show the order lines related to the sales order. If the sales order contains 10 order lines, the table in the generated report has 10 rows; if it contains two order lines, the table has two rows.
Add or edit a static table¶
To add a static table, type /
and select the Table command. Determine the number of
columns and rows for the table. Once the table has been added, you can start editing it.
You can insert, move and delete columns and rows using the table tools. Position the cursor on top of the column or to the left of the row then click the purple rectangle and select an option.

To resize a column, drag the column border to the desired position; reset all columns to their standard size by selecting Reset Size from the table tools.
Add the field of your choice in a cell or add static text by typing.
小訣竅
To add text in a structured way without using a table, you can use columns. Add columns by
typing /
and selecting the appropriate command: 2 columns, 3 columns or
4 columns.
添加或编辑动态表¶
備註
只有
one2many
或many2many
类型的关系才能显示为动态表。标准报表中现有的动态表比自己添加的动态表结构更复杂。对于这类表格,可以插入或删除列,但不能移动列或插入、移动或删除行。
要添加动态表,请键入 /
,然后选择 动态表格 指令。在打开的列表中,选择或搜索表格将基于的关系,然后按 回车
。表格添加完成后,就可以开始编辑了。
您可以使用表格工具插入、移动和删除列,就像 :ref:`静态表 <studio/pdf-reports/static-table>`一样。还可以插入静态行,这些行将出现在生成行的上方或下方。
To add a field to a cell, delete any placeholder text then add the field of your choice. The dialog box that opens shows the source object for the field (e.g., the Order Lines model) and the list of available fields.

用您选择的标签替换 列名 标签。
備註
默认行会自动遍历字段内容,为每个字段值在报告中生成一行(例如,每个订单行生成一行)。
格式設定¶
要格式化报告中的文本,请选择文本,然后使用 文本编辑器 中的选项格式化文本。
编辑报告的 XML¶
警告
直接修改 XML 可能会在 升级 时导致报告问题。如果出现这种情况,只需将旧数据库中的更改复制到升级后的数据库中即可。
要编辑报告的 XML,请点击左窗格中的 编辑来源。
例子¶
要更改报告中数据的显示方式,可以手动修改字段的默认 小部件 。在下面的示例中,订单日期默认显示日期和时间,而单价默认精确到小数点后两位。
<div class="oe_structure"> <span t-field="doc.date_order"/> <span t-field="doc.price_unit"/> </div>
通过使用 t-options`(本例中为 `小部件
选项),可以修改这些字段,使其分别只显示日期和小数点后四位的精度:
<div class="oe_structure"> <span t-field="doc.date_order" t-options="{'widget': 'date'}"/> <span t-field="doc.price_unit" t-options="{'widget': 'float', 'precision': 4}"/> </div>
如果要根据特定条件显示/隐藏内容,可以在报告 XML 中手动添加 if/else
控制语句。
例如,如果要在没有标记的情况下隐藏自定义数据表,可以使用 t-if
属性定义条件,然后将其评估为 True
或 False
。如果引号中没有标记,则不会显示表格。
<!-- table root element -->
<table class="table" t-if="len(doc.tag_ids) > 0">
<!-- thead = table header, the row with column titles -->
<thead>
<!-- table row element -->
<tr>
<!-- table header element -->
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<!-- table body, the main content -->
<tbody>
<!-- we create a row for each subrecord with t-foreach -->
<tr t-foreach="doc.tag_ids" t-as="tag">
<!-- for each line, we output the name and price as table cells -->
<td t-out="tag.id"/>
<td t-out="tag.name"/>
</tr>
</tbody>
</table>
如果想在 t-if
语句被评估为 False
时显示另一个块,可以使用 t-else
语句指定。在文档结构中,t-else`块必须直接跟在`t-if`块之后。无需在 `t-else
属性中指定任何条件。例如,让我们快速显示一条信息,说明引号上没有标记:
<!-- table root element -->
<table class="table" t-if="len(doc.tag_ids) > 0">
<!-- thead = table header, the row with column titles -->
<thead>
<!-- table row element -->
<tr>
<!-- table header element -->
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<!-- table body, the main content -->
<tbody>
<!-- we create a row for each subrecord with t-foreach -->
<tr t-foreach="doc.tag_ids" t-as="tag">
<!-- for each line, we output the name and price as table cells -->
<td t-out="tag.id"/>
<td t-out="tag.name"/>
</tr>
</tbody>
</table>
<div class="text-muted" t-else="">No tag present on this document.</div>
通过使用 `t-if/t-else`符号,报告编辑器可识别这些部分是互斥的,并应作为条件块显示:

您可以使用编辑器切换条件,预览它们的输出结果:

如果希望有多个选项,也可以使用 t-elif
指令添加中间条件。例如,销售订单报告的标题就是这样根据基础文档的条件而变化的。
<h2 class="mt-4">
<span t-if="env.context.get('proforma', False) or is_pro_forma">Pro-Forma Invoice # </span>
<span t-elif="doc.state in ['draft','sent']">Quotation # </span>
<span t-else="">Order # </span>
<span t-field="doc.name">SO0000</span>
</h2>
The title Pro-Forma Invoice is used depending on some contextual conditions. If these
conditions are not met and the state of the document is either draft
or sent
, then
Quotation is used. If none of those conditions are met, the report’s title is Order.
在报告中处理图片可能具有挑战性,因为对图片大小和行为的精确控制并不总是显而易见的。您可以使用报告编辑器插入图片字段(通过使用 字段指令),但使用 t-field
指令和附带的 t-options
属性在 XML 中插入图片可以提供更好的大小和定位控制。
例如,以下代码会将该行产品的字段 `image_128`输出为 64px 宽的图片(根据图片的宽高比自动调整高度)。
<span t-field="line.product_id.image_128" t-options-widget="image" t-options-width="64px"/>
图像部件有以下选项:
width
: width of the image, usually in pixels or CSS length units (e.g.,rem
) (leave empty for auto-width).height
: height of the image, usually in pixels or CSS length units (e.g.,rem
) (leave empty for auto-height).class
: CSS classes applied on theimg
tag; Bootstrap classes are available.alt
: alternative text of the imagestyle
: style attribute; it allows you to override styles more freely than with Bootstrap classes.
These attributes must contain strings, i.e., text enclosed within quotes within quotes, e.g.,
t-options-width="'64px'"
(or, alternatively, a valid Python expression).
備註
The image widget cannot be used on an img
tag. Instead, set the t-field
directive on a
span
(for inline content) or div
(for block content) node.
For example, let’s add a column with the product image in the quotation table:
<table class="table table-sm o_main_table table-borderless mt-4">
<thead style="display: table-row-group">
<tr>
<th>Image</th>
<th name="th_description" class="text-start">Description</th>
<th>Product Category</th>
<th name="th_quantity" class="text-end">Quantity</th>
<th name="th_priceunit" class="text-end">Unit Price</th>
[...]
<t t-foreach="lines_to_report" t-as="line">
<t t-set="current_subtotal" t-value="current_subtotal + line.price_subtotal"/>
<tr t-att-class="'bg-200 fw-bold o_line_section' if line.display_type == 'line_section' else 'fst-italic o_line_note' if line.display_type == 'line_note' else ''">
<t t-if="not line.display_type">
<td>
<span t-field="line.product_template_id.image_128"
t-options-widget="'image'"
t-options-width="'64px'"
t-options-class="'rounded-3 shadow img-thumbnail'"
/>
</td>
<td name="td_name"><span t-field="line.name">Bacon Burger</span></td>
<td t-out="line.product_id.categ_id.display_name"/>
The t-options-width
attribute restricts the image width to 64 pixels, and the Bootstrap classes
used in t-options-class
create a thumbnail-like border with rounded corners and a shadow.
