欄位及小工具

欄位為資料庫模型提供結構。如果將模型比喻為表格或試算表,欄位可理解為直欄,為不同記錄(橫列)儲存數據。欄位亦定義其儲存數據的類型。至於數據在 UI(操作介面) 上的顯示方式及格式,則由小工具定義。

技術上,Odoo 共有 15 種欄位類型。若使用 Studio,會有 20 種欄位可供選擇,因為有些欄位類型可在不同的預設小工具中多次使用。

小訣竅

新欄位 只可加入至 表單清單 檢視畫面。其他檢視畫面只可加入 現有欄位 (模型中已有的欄位)

簡單欄位

簡單欄位包括基本的資料值,例如文字、數字、檔案等。

備註

若有非預設的小工具可用,會在下方以點列符號或子標題的形式交代。

文字(char

文字 欄位適用於儲存任何字符的簡短文本。填寫這種欄位時,系統會顯示一行的文字輸入位置。

  • 徽章:在圓圈內顯示資料值,類似標籤。該值不可在操作介面上編輯,但可設定預設值。

  • 複製至剪貼板:使用者可按一下按鈕,複製該值。

  • 電郵:該值會變成可點按的 傳送電子郵件 (mailto)連結。

  • 圖片:顯示資料值網址的圖片。該值不可手動編輯,但可設定預設值。

    備註

    此方式與直接選擇 圖片欄位 不同。若使用附有 圖片 小工具的 文字 欄位,圖片不會儲存在 Odoo 中。舉例,如果想節省儲存空間,這方式會很有用。

  • 電話:該值會變成可點按的 撥打電話 (tel)連結。

    小訣竅

    勾選 啟用短訊 會加入選項,可直接在欄位旁邊,透過 Odoo 發送 SMS 電話短訊。

  • 網址:該值會變成可點按的 URL 網址。

Example

附有不同小工具的文字欄位範例

多行文字(text

多行文字 欄位適用於包含任何類型字符、字數較多的長文本。填寫該欄位時,操作介面會顯示兩行的文字輸入位置。

  • 複製至剪貼板:使用者可按一下按鈕,複製該值。

Example

附有不同小工具的多行文字欄位範例

整數(integer

整數 欄位適用於所有整數數字( 正數、負數或零,沒有小數部份 )。

  • 百分比圓形圖:以百分比圓形圖顯示數值,通常為計算得出的值。該值不可在操作介面上編輯,但可設定預設值。

  • 進度列:在百分比進度列旁邊顯示數值,通常為計算得出的值。該欄位不可手動編輯,但可設定預設值。

  • 把手:顯示拖曳把手圖示,用於在 列表檢視畫面 中,將記錄手動排序。

Example

附有不同小工具的整數欄位範例

小數(float

小數 (或稱浮點數)欄位,適用於所有小數數字( 正數、負數或零,帶有小數部份 )。

備註

小數在用戶操作介面上,會顯示為兩個小數位的小數,但在資料庫中,其實是以更高精確度儲存。

  • 貨幣金額:與使用 貨幣金額 欄位類似。建議使用後者,因為它提供較多功能。

  • 百分比:在數值後方顯示百分比符號 %

  • 百分比圓形圖:以百分比圓形圖顯示數值,通常為計算得出的值。該欄位不可手動編輯,但可設定預設值。

  • 進度列:在百分比進度列旁邊顯示數值,通常為計算得出的值。該欄位不可手動編輯,但可設定預設值。

  • 時間:數值必須為 hh:mm (小時:分鐘)格式,分鐘數值最大為 59。

Example

附有不同小工具的小數欄位範例

貨幣金額(monetary

貨幣金額 欄位適用於所有貨幣值。

備註

你首次加入 貨幣金額 欄位時,若模型未有 貨幣 欄位,系統會提示你加入貨幣欄位,以設定幣種。Odoo 可為你加入適用的 貨幣 欄位。完成後,便可加入 貨幣金額 欄位。

Example

貨幣金額欄位連同其貨幣欄位範例

HTML(html

HTML 欄位適用於加入可使用 Odoo HTML 編輯器編輯的文字。

  • 多行文字:會停用 Odoo HTML 編輯器,以便允許編輯 HTML 原文。

Example

附有不同小工具的 HTML 欄位範例

日期(date

日期 欄位可從日曆中選擇日期。

  • 剩餘天數:從目前日期起計,距離選取的日期還剩下多少天,例如: 剩餘 5 天 。此欄位應設為 唯讀

Example

附有不同小工具的日期欄位範例

日期時間(datetime

日期時間 欄位可從日曆中選擇日期,並從時鐘選擇時間。若未有設定時間,會自動採用使用者目前的時間。

小訣竅

一般屬性 外,設置了 日期時間日期範圍 小工具的 日期時間 欄位,有一些額外的 特定屬性 可用。

日期範圍(daterange

日期範圍 小工具適用於顯示包括開始日期及結束日期的時間段,以一行顯示全部資料。日期範圍可將開始及結束日期設為必填(例如:表示多天活動的日期),也可將開始或結束日期設為可選填(例如:用於上門介入工作或專案任務)。

加入日期範圍時,需要有兩個欄位:一個是附有 日期範圍 小工具的 日期時間 欄位,另一個是設為開始日期 結束日期的欄位。底層的參考欄位可以是現有的 日期日期時間 欄位,也可以是專門為此用途而建立的欄位。

要加入日期範圍:

  1. 確定一個現有的 日期日期時間 欄位,用作底層的開始或結束日期參考欄位,或新增一個欄位。如果日期範圍是:

    • 必須填寫開始及結束日期,此欄位可以是開始日期或結束日期,選擇兩者的結果相同。

    • 允許選填開始日期或結束日期,此欄位便會分別是開始日期或結束日期。

    小訣竅

    為避免重複顯示相同資訊,你可將底層的開始/結束日期欄位,設定為 不顯示,或按一下 從檢視中移除,將該日期從檢視畫面中移除,使之無法看見。

  2. 加入一個 日期時間 欄位,並將 小工具 欄位設定為 日期範圍

  3. 輸入適當的 標籤

  4. 根據需要,在 開始日期欄位結束日期欄位 下拉式選單中,選擇相應的底層開始/結束日期欄位。

  5. 若日期範圍必須包括開始日期及結束日期,請啟用 總是使用範圍

  6. 更新任何其他需要更新的 一般屬性日期時間欄位特定屬性,然後按一下畫面右上角的 關閉

Example

附有不同小工具的日期時間欄位範例

剩餘天數(remaining_days

剩餘天數 小工具顯示從目前的日期及時間起計,距離選取的日期還剩下多少天,例如: 剩餘 5 天 。此欄位應設為 唯讀

勾選方格(boolean

勾選方格 欄位適用於資料值只可以是「真」或「假」的情況,以方格有否被勾選去表示。

  • 按鈕:顯示為單選圓鈕。該小工具無需切換至編輯模式也可運作。

  • 切換:顯示為切換按鈕。該小工具無需切換至編輯模式也可運作。

Example

附有不同小工具的勾選方格欄位範例

選單(selection

選單 欄位適用於提供選項清單,用戶可從一組預先定義的值中,選擇其中一個值。

  • 徽章:在圓圈內顯示資料值,類似標籤。該值不可在操作介面上編輯,但可設定預設值。

  • 徽章:以長方形形狀顯示可選值,所有已選取的值會同時顯示,以水平方式排列。

  • 優先級別:顯示為星星圖示,而非數值,可用作表示重要程度或滿意度等。與選用 優先等級 欄位的效果相同,但後者已預先定義了 4 種優先級別數值。

  • 單選圓鈕:以單選圓鈕顯示可選的值,所有可選值會同時顯示。

    小訣竅

    預設情況下,單選圓鈕是以垂直方式排列。你可啟用 水平顯示 選項,以切換顯示方式。

  • 狀態列:以箭嘴進度列顯示可選值,所有可選值會同時顯示。

    小訣竅

    預設情況下,狀態列上的資料值可點按選取。你可停用 可點按 選項,防止使用者在操作介面編輯這些值。

Example

附有不同小工具的選單欄位範例

優先級別(selection

優先級別 欄位以三星評分格式顯示,可用作表示重要程度或滿意度。此欄位類型是 選擇欄位,預設會選取 優先級別 小工具,並有 4 個預先定義的優先級別值。故此, 徽章單選圓鈕選單 小工具的效果,與 選單 章節所述相同。

小訣竅

若要透過增加或刪除可選值,去更改可用的星星圖示數目,請按一下 編輯值。請留意,設定的首個資料值是等於 0 星,即未作選擇。因此,4 個可選值會顯示為 3 粒星的評分系統,如此類推。

Example

優先級別欄位範例

檔案(binary

檔案 欄位可用作上載任何類型的檔案,或用作簽署表單( 電子簽名 小工具)。

  • 圖片:使用者可上載圖片檔案,圖片隨後會在 表單檢視畫面 中顯示。與使用 圖片 欄位的效果相同。

  • PDF 檢視工具:使用者可上載 PDF 檔案,檔案上載後可在 表單檢視畫面 中瀏覽。

  • 電子簽名:使用者可透過電子形式簽署表單。與選擇 電子簽名 欄位的效果相同。

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.

小訣竅

要更改上传图片的显示大小,在:guilable:尺寸`选项下选择:guilabel:`小:guilale:`中`或:guilalb:`大`

签署(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.

小訣竅

To give users the Auto option when having to draw their signature, select one of the available Auto-complete with fields (Text, Many2One, and Related Field on the model only). The signature is automatically generated using the data from the selected field.

关系字段

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

備註

非默认小组件(如可用)显示为以下项目符号。

Many2One(many2one

:guilabel:`Many2One`字段用于将另一记录(来自另一模型)链接至正在编辑的记录。来自另一模型的记录名称将显示在正在编辑的记录中。

Example

在*销售订单*模型中,:guilable:`客户`字段为指向*联系人*模型的:guilabel:`Many2One`字段,允许**多个**销售订单链接至**一个**联系人(客户)。

显示many2one关系的图表

小訣竅

  • 要防止用户在链接的模型中创建新记录,勾选:guilable:禁用创建

  • 要防止用户在弹窗中打开记录,勾选:guilable:禁用打开

  • 要帮助用户只选择正确的记录,点击:guilable:,创建筛选器。

  • 标记:显示圈内值,类似于标记。该值不能在用户界面上编辑。

  • 單選圓鈕:以單選圓鈕顯示可選的值,所有可選值會同時顯示。

One2Many(one2many

:guilabel:`One2Many`字段用于显示当前模型中的记录和另一模型中的多个记录间的现有关系。

Example

您可以在*联系人*模型中添加:guilable:`One2Many`字段,以查看**一个**客户的**多个**销售订单。

显示one2many关系的图表

備註

To use a One2Many field, the two models must have been linked already using a Many2One field. One2Many relations do not exist independently: a reverse-search of existing Many2One relations is performed.

多行(one2many

:guilabel:`多行`字段用于创建有多行和多列的表格(例如,销售订单中的多个产品行)。

小訣竅

要修改列,点击:guilable:多行`字段,然后点击:gullable:`编辑列表视图。要编辑用户点击:guilable:Add a line`时弹出的表单,改为点击:gullable:`编辑表单视图

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

在*任务*模型中,:guilable:`受托人`字段为指向*联系人*模型的:guilabel:`Many2Many`字段,允许向单个用户分配**多个**任务,以及向**多个**用户分配给同一任务。

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

  • Tags: users can select several values appearing in rounded shapes, also known as tags. This has the same effect as selecting the Tags field.

标签(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.

小訣竅

要显示具有不同背景颜色的标记,勾选:guilable:使用颜色

Example

标记字段示例

屬性

General properties

  • Invisible: Enable this property when it is not necessary for users to view a field on the UI. This helps declutter the UI by only showing the essential fields depending on a specific situation.

    The Invisible attribute also applies inside Studio. To view hidden fields in Studio, click on a view’s View tab and enable Show Invisible Elements.

  • Required: Enable this property if a field should always be completed by the user before being able to proceed.

  • Readonly: Enable this property if users should not be able to modify a field.

備註

You can choose to enable Invisible, Required and Readonly for specific records only by clicking on Conditional and creating a filter.

Example

在*联系人*模型的*表单*视图中,:guilabel:`职务`字段仅在选择:guilabel:`个人`时显示,因为该字段对:guilabel:`公司`联系人无用。

  • Label: the field’s name on the UI. This is not the name used in the PostgreSQL database. To view and change the latter, activate the developer mode and edit the Technical Name.

  • Help Tooltip: To explain the purpose of a field, add a description. The text is displayed inside a tooltip box when hovering with your mouse over the question mark beside the field’s label.

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

  • Placeholder: To provide an example of how a field should be completed, add placeholder text. The text appears in light gray until a value is entered.

  • Default value: To display a default value in a field when a record is created, add a value.

  • Allow visibility to groups: To limit which users can view the field, select one or more user access groups.

  • Forbid visibility to groups: To prevent certain users from seeing the field, select one or more user access groups.

Properties for Date & Time fields

For Date & Time fields that have the Date & Time or Date Range widget set, some specific properties are available:

  • Time interval: Enter a value to determine the minute intervals shown in the time selector. For example, enter 15 to allow quarter-hour intervals. The default value is set to 5 minutes.

  • Warning for future dates: Enable this property to display a warning icon if a future date is selected.

  • Show time: This property is enabled by default for Date & Time fields. On a read-only field, disable the property to show only the date. This can keep a list view less cluttered, for example.

  • Earliest accepted date: Enter the earliest date that can be selected in the date selector in ISO-format, i.e., YYYY-MM-DD. If the current date is always the earliest accepted date, enter today. On the date selector, dates prior to the earliest accepted date are grayed out.

  • Latest accepted date: Enter the latest date that can be selected in the date selector in ISO-format, i.e., YYYY-MM-DD. If the current date is always the latest accepted date, enter today. On the date selector, dates later than the latest accepted date are grayed out.