欄位及小工具

Fields structure the models of a database. If you think of a model as a table or spreadsheet, fields are the columns and records are the individual rows. Fields also define the type of data that is stored within them. The way in which a field’s data is presented and formatted on the UI is controlled by its widget.

With Studio, it is possible to:

Studio fields vs. property fields

Fields created using Studio are saved as columns in your Odoo database. Property fields, on the other hand, act as pseudo-fields; they are shared by all records that are linked to the same parent record (e.g., for tasks, the project, or for a product, the product category), but they are not saved as columns in your database.

Example

Adding a Deadline field to the form view of a task using Studio makes that field visible in every task in your database. Adding a Special instructions property field to a task makes the field visible in all tasks within the same project (i.e., its parent) while other projects’ tasks remain unaffected.

Field types

Fields can be broadly divided into two categories:

  • Simple fields, which contain basic values, such as text, numbers, files, etc.

  • Relational fields, which are used to link and display the data from records on another model.

簡單欄位

備註

Non-default widgets, when available, are presented as bullet points or sub-headings.

文字(char

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

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

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

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

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

    備註

    This works differently from selecting the Image field directly, as the image is not stored in Odoo when using a Text field with the Image widget. For example, it can be useful if you want to save disk space.

  • 電話:該值會變成可點按的 撥打電話 (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

圖片 欄位可用作上載圖片,並在 表單檢視畫面 中顯示。此欄位類型是 檔案 欄位,預設已選取 圖片 小工具。故此,檔案PDF 檢視工具電子簽名 小工具的效果,與 檔案 章節所述相同。

小訣竅

若要變更上載圖片的顯示大小,請在 大小 選項下,選擇

電子簽名(binary

電子簽名 欄位適用於透過電子形式簽署表單。此欄位類型是 檔案 欄位,預設已選取 電子簽名 小工具。故此,檔案圖片PDF 檢視工具 小工具的效果,與 檔案 章節所述相同。

小訣竅

若想讓使用者在繪製簽名時可使用 自動完成 功能,請選擇其中一個可用的 自動完成依據 欄位(只限模型中的 文字多對一(Many2One)相關欄位)。系統會使用所選欄位的資料,自動產生簽名圖樣。

關係欄位

備註

Non-default widgets, when available, are presented as bullet points or sub-headings.

多對一 Many2One(many2one

多對一 (Many2One)欄位適用於將另一項記錄(儲存於另一模型)連結至正在編輯的記錄。使用的另一模型記錄名稱,會於正在編輯的記錄中顯示。

Example

舉例,在 銷售單 模型中,客戶 欄位其實是指向 聯絡人 模型的 多對一 欄位。「多對一」的意思,是允許 多張 銷售單連結至 同一名 聯絡人(即客戶)。

展示多對一關係的示意圖

小訣竅

  • 若要防止使用者在已連結的模型中建立新的記錄,可勾選 禁止建立

  • 若要防止使用者以彈出視窗開啟記錄查看,可勾選 禁止開啟

  • 為協助使用者選取正確的記錄,請按一下 範圍,以建立篩選器。

  • 徽章:以圓角形狀顯示資料值,類似標籤。該值不可在操作介面上編輯。

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

一對多 One2Many(one2many

一對多 (One2Many)欄位可用作顯示目前模型內的記錄與另一模型中多項記錄之間,已存在的現有關係。

Example

例如,你可在 聯絡人 模型中加入 一對多 欄位,便可查看 一名 個別客戶的 多張 銷售單。

展示一對多關係的示意圖

備註

要使用 一對多 欄位,兩個模型必須已透過 多對一欄位 連結。一對多關係不會獨立存在,系統會進行反向搜尋,尋找目前已有的多對一關係。

資料行(one2many

資料行 欄位是用於建立由資料列(橫列)及直欄構成的表格,例如銷售單的產品資料行。

小訣竅

若要修改直欄,請按一下 資料行 欄位,然後按 編輯列表檢視。若要編輯使用者按下 加入資料行 時彈出的表單,請按一下 編輯表單檢視

Example

資料行欄位範例

多對多(many2many

多對多 (Many2Many)欄位用於將另一模型中的多項記錄,連結至目前模型中的多項記錄。與 多對一 欄位一樣,多對多欄位也可使用 禁止建立禁止開啟範圍 功能。

Example

舉例,在 任務 模型中, 受指派人 欄位是一個指向 聯絡人 模型的 多對多 欄位。這樣便可允許一名使用者被指派至 多項 任務,同時也允許 多名 使用者被指派至同一個任務。

展示多對多關係的示意圖
  • 勾選方格:使用者可使用勾選方格,選取多個值。

  • 標籤:使用者可選取多個以圓角形狀顯示的值,這些值也稱為「標籤」。這與選用 標籤 欄位的效果相同。

標籤(many2many

標籤 欄位可用於顯示多個來自另一模型的值,這些值以圓角形狀顯示,也稱為 標籤 。此欄位類型是 多對多欄位,預設已選取 標籤 小工具。故此, 勾選方格多對多 小工具的效果,與 多對多 章節所述相同。

小訣竅

若要使用不同背景顏色顯示不同標籤,請勾選 使用顏色

Example

標籤欄位範例

Add a field to a view

With Studio, it is possible to add:

小訣竅

Add a new field to a form or list view to save it to the model and make it available as an existing field in other views of the same model.

Add a new field

小訣竅

Activate developer mode before adding a new field to see, and be able to edit, the field’s technical name during configuration.

To add a new field, follow these steps:

  1. Navigate to the relevant form or list view, then click the (Toggle Studio) icon in the upper-right corner. Alternatively, with any app open, click the (Toggle Studio) icon, then navigate to the relevant form or list view.

  2. In the Add tab, drag the relevant field type from the New Fields section and drop it in the desired position. If the new field is a relational field, select the relevant reciprocal field, model, or related field in the pop-up.

  3. In the Properties tab, configure the field’s properties:

    • Enter the Label to be displayed as the field name on the UI; this is also used to generate the default technical name of the field.

    • Click anywhere outside the Label field to see the Technical Name updated with the default technical name.

      備註

      • The Technical Name of a new field can be edited in Studio during the configuration process. At any other time, a field’s technical name can only be modified via the technical settings of the database.

      • The technical name of a new field added using Studio is by default prefixed by x_studio_.

    • Optionally, select a different Widget via the dropdown; the default widget for the field type is selected by default.

    • Optionally, configure any other field properties.

  4. Click Close in the top-right corner to close Studio.

Add an existing field

To add a field that exists on the model but that is not present on the current view, follow these steps:

  1. Navigate to the relevant view, then click the (Toggle Studio) icon in the upper-right corner. Alternatively, with any app open, click the (Toggle Studio) icon, then navigate to the relevant view.

  2. In the Add tab, in the left panel, click Existing Fields to reveal a list of all the model’s fields that are not currently present in the view.

  3. Drag the relevant field and drop it in the desired position.

  4. In the Properties tab, configure the relevant properties for the field in the current view.

    備註

    Various properties can be configured independently for different views, if needed, such as the Label, the Widget, the visibility of the field for certain user groups, as well as whether or not the field is Invisible, Required, or Readonly.

  5. Click Close in the top-right corner to close Studio.

Field properties

A series of general properties can be configured for most combinations of field type and widget. Additional properties are available depending on the specific field type and widget selected. For example, Date & Time fields using the Date & Time or Date Range widget have various specific properties that can be configured.

一般屬性

  • Class: Use Bootstrap or other custom classes defined in Odoo to customize how the field is styled and displayed on the UI.

  • 隱藏:若使用者無需在操作介面看到該欄位,便可啟用此屬性。這有助簡化使用者操作介面,只會顯示個別情況需要顯示的欄位。

  • 必填:若使用者必須先完成填寫該欄位才可繼續操作,可啟用此屬性。

  • 唯讀:若不應讓使用者修改該欄位,可啟用此屬性。

小訣竅

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

  • The Invisible, Required, and Readonly properties can be enabled for specific records only by clicking on Conditional and creating a filter.

    Example

    On the form view of the Contact model, the Title field only appears when Individual is selected, as that field would not be helpful for a Company contact.

  • Label: This is the field name on the UI; the label is used to generate the technical name of the field.

  • 幫助提示:若想提供註釋,解釋欄位的用途,可加入工具提示描述。使用者以滑鼠停留在欄位顯示標籤旁邊的問號圖示時,便會出現提示文字,以工具提示方塊顯示。

  • Technical Name: To view a field’s technical name in Studio (and, during the configuration of a new field, edit it if desired), activate developer mode.

    小訣竅

    If this field needs to be updated but is no longer editable via Studio, the technical name can be modified via the technical settings of the database.

  • 小工具:若要變更欄位的預設外觀或功能,可選用其中一個可用的小工具。

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

  • Dynamic Placeholder: To provide the value of the selected field as an example of how a field should be completed. The text appears in light gray until a value is entered.

  • 預設值:若要在建立記錄時,在欄位中顯示預設值,可加入此值。

  • 允許向群組顯示:若想限制哪些使用者可看見此欄位,可選取一個或多個「使用者存取 群組 」。

  • 禁止向群組顯示:若想防止部份使用者看見此欄位,可選取一個或多個「使用者存取 群組 」。

日期時間欄位屬性

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

  • Minimal precision: Determine the smallest date unit that must be selected in the date selector. The possible values are Day, Month, Year or Decade. If no value is selected, the user must select a day in the date selector.

  • Maximal precision: Determine the largest date unit that can be used to navigate the date selector. The possible values are Day, Month, Year or Decade. If no value is selected, the user can navigate the date selector by decade.

  • 警告未來日期:啟用此屬性後,若選取了未來日期,系統會顯示警告圖示。

  • 精簡顯示:啟用此屬性後,日子、月份及小時的數字前方,將不會顯示 0(零)。例如:會顯示為 4/2/2025 8:05:00 而非 04/02/2025 08:05:00

  • 顯示時間日期時間 欄位預設會啟用此屬性。對於唯讀欄位,停用此屬性會只顯示日期。舉例,如此設定可使列表檢視畫面較簡潔。

  • 顯示秒數日期時間 欄位預設會啟用此屬性。若想只顯示小時及分鐘,可停用此屬性。

  • 時間間隔:此值決定時間選擇器所顯示的分鐘間隔。例如:輸入「15」可設定每隔 15 分鐘有可選時間。預設值為 5 分鐘。

  • 最早接受日期:日期選擇器可選取的最早日期,以 ISO 格式輸入,即 YYYY-MM-DD (年年年年-月月-日日)。若最早接受的日期必定是目前日期,請輸入 today (今天)。在日期選擇器中,最早接受日期之前的日期會以灰色顯示。

  • 最遲接受日期:日期選擇器可選取的最遲日期,以 ISO 格式輸入,即 YYYY-MM-DD (年年年年-月月-日日)。若最遲接受的日期必定是目前日期,請輸入 today (今天)。在日期選擇器中,最遲接受日期之後的日期會以灰色顯示。

Modify a field’s properties

To modify the properties of a field, follow these steps:

  1. Navigate to the relevant view, then click the (Toggle Studio) icon in the upper-right corner. Alternatively, with any app open, click the (Toggle Studio) icon, then navigate to the relevant view.

  2. Click on the relevant field.

  3. In the Properties tab, make any desired changes to the field properties.

    小訣竅

    Various properties can be configured independently for different views, such as the Label, the Widget, the visibility of the field for certain user groups, as well as whether or not the field is Invisible, Required, or Readonly.

  4. Click Close in the top-right corner to close Studio.

備註

The Technical Name of a field (visible in Studio with developer mode activated) cannot be modified in Studio; this can be done via the technical settings of the database.

Modify a field’s technical name

To modify the technical name of a field, activate developer mode, then follow these steps:

  1. With the field open in Studio, copy the technical name of the field.

  2. Remove the field from all views in Studio, then click Close to close Studio.

  3. Navigate to Settings app ‣ Technical ‣ Fields.

  4. Paste the copied technical name into the search bar, then open the relevant field.

  5. Modify the Field Name as needed.

Once the field’s technical name has been updated, the field can then be added (back) to the relevant view(s) from the list of existing fields.

重要

When updating the technical name of a field, make sure to keep at least the x_ prefix, which is required for any custom field; for fields created using Studio, keep the x_studio_ prefix to allow such fields to be more easily identified.

Remove a field from a view

To remove a field from a view, follow these steps:

  1. Navigate to the relevant view, then click the (Toggle Studio) icon in the upper-right corner. Alternatively, with any app open, click the (Toggle Studio) icon, then navigate to the relevant view.

  2. Click on the relevant field.

  3. Scroll to the bottom of the Properties tab, then click Remove from view.

  4. Click Ok to confirm the action.

小訣竅

  • A removed field can be easily added back to the view at a later stage, if needed.

  • If the intention is to declutter the view, it is also possible to modify a field and make it Invisible on the view in question.