字段和小部件

字段结构化数据库模型。如果你把模型想象成一个表格或电子表格,字段就是记录中存储数据的列(即行)。字段还定义了存储在其中的数据类型。数据在 UI 上的呈现和格式化由它们的小部件定义。

从技术角度来看,Odoo有15种字段类型。然而,在Studio中,您可以选择20种字段类型,因为某些字段类型具有不同的默认小部件而可用多次。

小技巧

新字段`只能添加到 :ref:`studio/views/general/form列表 视图中。在其他视图中,您只能添加 现有字段 (已经在模型上的字段)

简单字段

简单字段包含基本值,如文本、数字、文件等。

注解

如果有非默认的小部件可用,则会将其作为项目符号列在下面。

文本 (char)

The Text field is used for short text containing any character. One text line is displayed when filling out the field.

  • 徽章: 在一个圆形的形状内显示值,类似于一个标签。该值不能在用户界面上编辑,但可以设置默认值。

  • 复制到剪贴板: 用户可以通过点击按钮复制该值。

  • 电子邮件:该值将变为可点击的 mailto 链接。

  • Image: 使用URL显示图像。该值无法手动编辑,但可以设置默认值。

    注解

    这与直接选择 Image field 不同,因为当使用 Text 字段和 Image 小部件时,图像不会存储在 Odoo 中。 例如,如果您想要节省磁盘空间,这可能会很有用。

  • 电话: 值变成可点击的 tel 链接。

    小技巧

    勾选 启用短信,在字段旁边添加一个直接从Odoo发送短信的选项。

  • URL:该值将变为可点击的URL。

Example

不同小部件的文本字段示例

多行文本 (text)

The Multiline Text field is used for longer text containing any type of character. Two text lines are displayed on the UI when filling out the field.

  • 复制到剪贴板: 用户可以通过点击按钮复制该值。

Example

不同小部件的多行文本字段示例

整数 (integer)

整数字段用于所有整数数字(正数、负数或零,不包括小数点)。

  • 百分比饼图: 在一个百分比圆圈内显示值,通常用于计算值。该值无法在用户界面上编辑,但可以设置默认值。

  • 进度条: 在百分比条旁边显示值,通常用于计算值。该字段不能手动编辑,但可以设置默认值。

  • Handle: 显示一个拖动手柄图标,用于在 列表视图 中手动排序。

Example

不同小部件的整数字段示例

Decimal (float)

The Decimal field is used for all decimal numbers (positive, negative, or zero, with a decimal).

注解

小数在用户界面上显示为小数点后两位,但在数据库中存储时具有更高的精度。

  • 货币: 它与使用 货币字段 类似。建议使用后者,因为它提供了更多的功能。

  • 百分比: 在值后显示一个百分号 %

  • 百分比饼图: 在百分比圆圈内显示值,通常用于计算值。该字段无法手动编辑,但可以设置默认值。

  • 进度条: 在百分比条旁边显示值,通常用于计算值。该字段不能手动编辑,但可以设置默认值。

  • 时间:值必须遵循 hh:mm 格式,最多为 59 分钟。

Example

不同小部件的十进制字段示例

货币 (monetary)

The Monetary field is used for all monetary values.

注解

当您首次添加一个 Monetary 字段时,如果模型上还不存在 Currency 字段,系统会提示您添加一个 Currency 字段。Odoo 会为您提供添加 Currency 字段的选项。一旦添加了 Currency 字段,再次添加 Monetary 字段。

Example

货币字段示例及其货币字段

HTML( html

The Html field is used to add text that can be edited using the Odoo HTML editor.

  • 多行文本:禁用Odoo HTML编辑器以允许编辑原始HTML。

Example

不同小部件的Html字段示例

日期 (date)

The Date field is used to select a date on a calendar.

  • Remaining Days: the remaining number of days before the selected date is displayed (e.g., In 5 days), based on the current date.

Example

不同小部件的日期字段示例

日期和时间 (datetime)

The Date & Time field is used to select a date on a calendar and a time on a clock. The user’s current time is automatically used if no time is set.

  • 日期: 用于记录时间,但不在用户界面上显示。

  • Remaining days: displays the remaining number of days before the selected date (e.g., In 5 days), based on the current date and time.

Example

不同小部件的日期和时间字段示例

复选框 (boolean)

The Checkbox field is used when a value should only be true or false, indicated by checking or unchecking a checkbox.

  • Button: 显示一个单选按钮。小部件在不切换到编辑模式的情况下工作。

  • Toggle: 显示一个切换按钮。该小部件在不切换到编辑模式的情况下工作。

Example

不同小部件的复选框字段示例

选择 (selection)

The Selection field is used when users should select a single value from a group of predefined values.

  • 徽章: 在一个圆形的形状内显示值,类似于一个标签。该值不能在用户界面上编辑,但可以设置默认值。

  • 徽章: 在矩形形状内同时显示所有可选择的值,水平排列。

  • 优先级: 显示星号符号而不是值,可以用来表示重要性或满意度水平,例如。这与选择:ref:`优先级字段 <studio/fields/simple-fields/priority>`具有相同的效果,尽管对于后者,已经预定义了四个优先级值。

  • 单选按钮: 以单选按钮的形式同时显示所有可选择的值。

    小技巧

    默认情况下,单选按钮是垂直排列的。勾选 水平显示 可以切换它们的显示方式。

Example

不同小部件的选择字段示例

优先级 (selection)

The Priority field is used to display a three-star rating system, which can be used to indicate importance or satisfaction level. This field type is a Selection field with the Priority widget selected by default and four priority values predefined. Consequently, the Badge, Badges, Radio, and Selection widgets have the same effects as described under Selection.

小技巧

要通过添加或删除值来更改可用星级的数量,请单击 Edit Values。请注意,第一个值等于0颗星(即未进行选择时),因此有四个值会导致三颗星的评级系统,例如。

Example

优先级字段示例

文件 (binary)

The File field is used to upload any type of file, or sign a form (Sign widget).

  • Image: 用户可以上传一个图片文件,然后在 Form view 中显示。这与使用 Image field 有相同的效果。

  • PDF Viewer: 用户可以上传PDF文件,然后可以从:ref:`Form view <studio/views/general/form>`中浏览。

  • 签名: 用户可以电子签名表单。这与选择 签名字段 有相同的效果。

Example

不同小部件的文件字段示例

图像 (binary)

The Image field is used to upload an image and display it in Form view. This field type is a File field with the Image widget selected by default. Consequently, the File, PDF Viewer, and Sign widgets have the same effects as described under File.

小技巧

要更改上传图像的显示大小,请在 Size 选项下选择 SmallMediumLarge

签名 (binary)

The Sign field is used to sign the form electronically. This field type is a File field with the Sign widget selected by default. Consequently, the File, Image, and PDF Viewer widgets have the same effects as described under File.

小技巧

为了在用户需要绘制签名时提供 Auto 选项,选择可用的 Auto-complete with 字段(仅在模型上选择 TextMany2One,和 Related Field)。签名将自动使用所选字段的数据生成。

关联字段

关系字段用于链接和显示另一个模型上的记录数据。

注解

如果有非默认的小部件可用,则会将其作为项目符号列在下面。

Many2One (many2one)

The Many2One field is used to link another record (from another model) to the record being edited. The record’s name from the other model is then displayed on the record being edited.

Example

销售订单 模型中, Customer 字段是一个 Many2One 字段,指向 Contact 模型。这允许 多个 销售订单链接到 一个 联系人(客户)。

显示多对一关系的图表

小技巧

  • 要防止用户在关联模型中创建新记录,请勾选 禁用创建

  • 要防止用户在弹出窗口中打开记录,请勾选 禁用打开

  • 为了帮助用户只选择正确的记录,请点击 Domain 来创建一个过滤器。

  • 徽章: 在一个圆形的形状内显示值,类似于一个标签。该值无法在用户界面上进行编辑。

  • 单选按钮: 以单选按钮的形式同时显示所有可选择的值。

One2Many (one2many)

The One2Many field is used to display the existing relations between a record on the current model and multiple records from another model.

Example

您可以在 联系人 模型上添加一个 One2Many 字段来查看 一个 客户的 多个 销售订单。

显示一对多关系的图表

注解

要使用 One2Many 字段,两个模型必须已经使用 Many2One 字段 进行了链接。One2Many 关系不能独立存在:会执行一个反向搜索已有的 Many2One 关系。

Lines (one2many)

The Lines field is used to create a table with rows and columns (e.g., the lines of products on a sales order).

小技巧

要修改列,请单击 Lines 字段,然后单击 Edit List View。要编辑用户单击 Add a line 时弹出的表单,请单击 Edit Form View

Example

多行文本框示例

Many2Many (many2many)

The Many2Many field is used to link multiple records from another model to multiple records on the current model. Many2Many fields can use Disable creation, Disable opening, Domain, just like Many2One fields.

Example

Task 模型上, Assignees 字段是一个 Many2Many 字段,指向 Contact 模型。这允许一个 单个用户被分配给 多个 任务,以及 多个 用户被分配给一个单个任务。

显示多对多关系的图表
  • 复选框: 用户可以使用复选框选择多个值。

  • 标签: 用户可以选择出现在圆形形状中的多个值,也称为*标签*。这与选择 标签字段 有相同的效果。

标签 (many2many)

The Tags field is used to display several values from another model appearing in rounded shapes, also known as tags. This field type is a Many2Many field with the Tags widget selected by default. Consequently, the Checkboxes and Many2Many widgets have the same effects as described under Many2Many.

小技巧

要显示具有不同背景颜色的标签,请勾选 使用颜色

Example

标签字段示例

属性

  • 不可见: 当用户在UI上不需要查看字段时,勾选 不可见。它通过仅显示与特定情况相关的必要字段来清除UI界面。

    Example

    联系人 模型的 表单 视图中,只有在选择 个人 时, Title 字段才会出现,因为该字段对于 公司 联系人没有帮助。

    注解

    属性 Invisible 也适用于 Studio。要在 Studio 内查看隐藏的字段,请点击视图的 View 选项卡并勾选 Show Invisible Elements

  • 必填: 如果一个字段在用户能够继续之前必须始终由用户填写完毕,请勾选 必填

  • 只读: 如果用户不应该能够修改字段,请勾选 只读

    注解

    你可以通过点击 Conditional 并创建一个过滤器,选择仅对特定记录应用这三个属性。

  • 标签: 标签 是字段在用户界面上的名称。

    注解

    这个名称与 PostgreSQL 数据库中使用的名称不同。要查看和更改后者,请激活 开发者模式,然后编辑 技术名称

  • 帮助工具提示: 为了解释字段的目的,在:guilabel:`帮助工具提示`下写一个描述。当鼠标悬停在字段的标签上时,它会显示在一个工具提示框内。

  • 占位符: 为了提供一个字段应该如何填写的示例,将其写在 占位符 下面。它以浅灰色显示,代替字段的值。

  • Widget: 要更改字段的默认外观或功能,请选择其中一个可用的小部件。

  • 默认值: 在创建记录时为字段添加默认值,请使用 默认值

  • 限制可见性为组: 为了限制哪些用户可以看到该字段,选择一个用户访问组。