高级用例:创建模型和添加字段

  • 高级用例:创建模型和添加字段

在你的线索的表格上,添加 Related FieldCountry > Country Name.
现在,添加一个 Checkbox 字段并将其隐身选项定义为 Country (仔细选择刚刚创建的字段)*> is not = > France.*
如果您愿意,现在可以隐藏创建的相关字段 (Country)。
View of the invisibility domain of a field being set in Odoo Studio
另一种方法就是使用该国的 ID。为此,请转到 :菜单选择:Contacts --> Configuration --> Countries,选择法国(例如),并在 URL 上检查其 ID
相关的字段隐身路径现在应为 Country*(仔细选择刚刚创建的字段)> is not = > 75*.
同样,如果您愿意,请使用国家/地区 ID 隐藏相关字段。
View of an URL emphasizing where a country’s ID can be found for Odoo Studio
  • Case scenario 2: create a model called ‘Properties’ and add fields called: company, value, name, address, active, image.

从仪表板(可选)启动新模块。然后,单击 Edit Menu and start a New Menu (model). 设置菜单名称和 Confirm.现在,在其窗体上,拖放必要的字段。

View of the recommended fields for an object in Odoo Studio
  • Case scenario 2.a: now, you would like to have a model called ‘Regions’ to which each property must be linked. And, on ‘Regions’, you would like to see the properties for each region.

转到*Edit Menu > New Menu*并创建菜单,称之为 Regions。通过拖放和删除窗体上添加必要的字段。
现在,在 Properties 窗体视图中,添加一个*Many2one* 字段,该字段与模型 *Region*相关。

小技巧

Existing Fields 是当前模型上但尚未在视图中的字段。

Form view and a Many2one field being dropped in Odoo Studio
Form view and a Many2one field being dropped in Odoo Studio
现在,转到模型 Regions,选择窗体视图,并添加一个状态按钮,选择 *Regions (Properties)*作为关系字段。
Status buttons 是计算字段,这意味着它们计算相关模型上的记录数,并允许您访问它们。
Form view and the status button window being shown in Odoo Studio

小技巧

搜索关系时,单击 Search more*并按*Custom 筛选它。这样,您就避免了创建重复项。

View of the search model window in Odoo Studio
  • Case scenario 2.b: in the model ‘Properties’, show all the tags as checkboxes instead of tags.

将字段 Tags 添加到窗体后,选择它,下其 Properties > Widgets,选择*Checkboxes*。

Form view showing the widgets available in Odoo Studio
  • Case scenario 3: on the leads’ form, add a selection field with the values:’Tags’ & ‘List’ & ‘Checkboxes’. According to the value of the field, show tags as many2many_tags, many2many_radio, or many2many(_list).

在表单视图中,添加*Tags* 字段并将其与 Partners Tag.关联。在 Properties 下,将其*Widget* 定义为 Many2many 。对*Checkboxes* 和 *Tags*再执行 2 次相同的过程。

Form view emphasizing the widget property in Odoo Studio
现在,添加 Selection 字段和必要的值。
继续选择您的 Tags 字段,一个一个,以设置其*Invisible* 选项根据其 Widget。在下面的示例中, Partner Tags 的隐身规则设置为: Select Tag type > is not = > Tags.
Form view emphasizing a field added and its invisibility properties in Odoo Studio
  • Case scenario 4: on a quotation’s form, add a selection field called ‘Manager Validation’ with the values: ‘Accepted’ and ‘Refused’. Only a sales manager can see it, and the field should be set as mandatory if the untaxed amount is higher than 500€.

在报价单上添加一个*Selection* 字段,该字段的值为*Accepted*和*Refused*。将其 *Required*条件设置为 *Untaxed Amount > 500*和 *Limit visibility to groups*作为 *Sales / Administrator*或经理的可见性。

Form view of a required domain being set in Odoo Studio
  • Case scenario 5: change the tooltip of a field for all views.

Activate the developer mode and open Studio.
选择必要的字段,并在*Properties* 下单击*More*在 *Field Help*上书写工具提示消息。工具提示消息是用户悬停字段时显示的解释性消息。此处写入的消息将显示在添加字段的所有视图窗体上。
Form view showing more property options and emphasizing the help feature in Odoo Studio

注解

Field Help 消息只能应用于 new 字段。如果要更改/应用特定字段的工具提示,请使用 Properties*下的 *Help Tooltip 选项。

View of the properties emphasizing the help tooltip option in Odoo Studio