自定义报表

Odoo 使用 HTML 和 CSS 技术创建报表。HTML 是一种使用标记(也称为元素)的标记语言。它是任何网页的核心,因为它提供了其基本结构。CSS 与 HTML 元素交互,以向页面添加样式,从而确定向用户显示 HTML 的方式。Odoo 的报告还使用 Bootstrap 的网格布局,即容器、行和列来对齐内容,并支持 Odoo 的网站主题。
创建新报表时,请选择其用途,如果希望报表包含页眉和页脚(公司徽标、名称、地址、电话、电子邮件地址等)。
View of the types of new reports in Odoo Studio

在选项卡**Add**下,您可以找到要拖动的字段并将其拖到视图中。Fields, Data tables, Subtotal & Total, 和 Address Book*是动态元素 (这意味着他们需要一个 :doc:`one2many or a many2many <../concepts/understanding_general>`相关对象)。 *Text, Title Block, Image,和*Text in Cell*是静态元素。

View of a report and the tab add in Odoo Studio

将元素添加到视图中后,选择它以查看其**Options**。第一部分显示所选对象的层次结构及其属性,允许您单独编辑它们。具有相关对象的字段的指令显示在*Field Expression*。

View of a report and the tab options in Odoo Studio
**Visible if**下,定义规则以将可见性条件设置为字段。
示例:如果选择显示产品图像,可以设置可见性规则,以便仅在产品窗体中显示*set* 的图标,避免在未设置时具有纯图标。
Visible for is used to set which groups can have access to specific elements in the report. Limit visibility to groups, under Report, sets the visibility of the report to specifics groups, meaning that users belonging to other groups do not see the same final document.
View of a report’s settings emphasizing the field limit visibility to groups in Odoo Studio

**Report**选项卡下,命名报表,选择纸张格式,以及报告是否应添加到相应文档窗体上的 Print 菜单列表中。

View of an invoice form emphasizing the menu print for Odoo Studio

If activating the developer mode, additional fields such as Class under Options, and Reload from attachment under Report, become visible.

  • Class: 将自定义 CSS 类添加到所选元素 (e.g. Bootstrap classes such as text-danger).

  • Reload from attachment: 打印时将报表保存为文档的附件。重印报表时,它会重新下载该附件,而不是重新打印。这意味着,如果基础记录(例如发票)与第一次展示结果相比发生更改,则报表不会反映更改,因为它们是在创建附件后完成的。这通常适用于链接到不应更改的文档(如发票)的报表。

小技巧

在您关闭工具箱之前,可以撤消 Odoo 工作室中的操作。 Close Studio 后,不能再撤消更改。

View of a report being built and emphasizing the undo and redo buttons in Odoo Studio