View architectures

Generic architecture

The architecture of a view is defined by XML data interpreted by the JavaScript framework.

For most views, there is a *.rng file defining the attributes and possible architectures. Some views are not ruled by such a file either because they accept HTML content, or for performance reasons.

注解

The current context and user access rights may impact the view abilities.

另请参阅

View records

Python表达式

When evaluating node attributes, e.g. the readonly modifier, it is possible to provide a Python expression that will be executed in an environment that has access to the following variables:

  • The names of all fields present in the current view, containing the value of the current record, except for column_invisible in list view; relational fields are given as a list of IDs;

  • The ID of the current record;

  • parent: the record that refers to the container; only inside sub-views of relational fields;

  • context (dict): the current view’s context;

  • uid (int): the id of the current user;

  • today (str): the current local date in the YYYY-MM-DD format;

  • now (str): the current local datetime in the YYYY-MM-DD hh:mm:ss format.

Example

<field name="field_a" readonly="True"/>
<field name="field_b" invisible="context.get('show_me') and field_a == 4"/>

Example

<field name="field_a"/>
<field name="x2m">
    <!-- sub-view -->
    <form>
        <field name="field_b" invisible="parent.field_a"/>
    </form>
</field>

表单

Form views are used to display the data from a single record. They are composed of regular HTML with additional semantic and structural components.

The root element of form views is form.

<form>
    ...
</form>

Root attributes

Optional attributes can be added to the root element form to customize the view.

string

The view title. It is displayed only if you open an action that has no name and whose target is new (opening a dialog).

Requirement

可选的

类型

str

默认

''

create

禁用/启用视图上的记录创建。

Requirement

可选的

类型

bool

默认

True

edit

Disable/enable record edition on the view.

Requirement

可选的

类型

bool

默认

True

duplicate

通过 操作 下拉菜单在视图上禁用/启用记录复制。

Requirement

可选的

类型

bool

默认

True

delete

Disable/enable record deletion on the view through the Action dropdown.

Requirement

可选的

类型

bool

默认

True

js_class

The name of the JavaScript component the webclient will instantiate instead of the form view.

Requirement

可选的

类型

str

默认

''

disable_autofocus

Disable automatic focusing on the first field in the view.

Requirement

可选的

类型

bool

默认

False

语义组件

Semantic components tie into the Odoo system and allow interaction with it.

Form views accept the following children semantic components: field, label, button, Chatter widget, and Attachments preview widget.

Placeholders are denoted in all caps.

field: display field values

The field element renders (and allows editing of, possibly) a single field of the current record.

Using the same field multiple times in a form view is supported, and the fields can receive different values for the invisible and readonly attributes. These fields may have the same values but can be displayed differently. However, the behavior is not guaranteed when several fields exist with different values for the required attribute.

<form>
    <field name="FIELD_NAME"/>
</form>

The field element can have the following attributes:

name

The name of the field to render.

Requirement

强制性的

类型

str

widget

The widget used to represent the field. The selected widget can change the way the field is rendered and/or the way it can be edited. It refers to a Javascript implementation (an Owl component) registered to the fields registry.

Requirement

可选的

类型

str

id

The node id. Useful when there are several occurrences of the same field in the view (see label: display field labels).

Requirement

可选的

类型

str

默认

The field name

string

The label of the field.

Requirement

可选的

类型

str

默认

The string attribute of the model’s field

help

The tooltip displayed when hovering the field or its label.

Requirement

可选的

类型

str

默认

''

options

The configuration options for the field’s widget (including default widgets), as a Python expression that evaluates to a dict.

For relation fields, the following options are available: no_create, no_quick_create, no_open, and no_create_edit.

Example

<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'FIELD_NAME', 'no_quick_create': True}"/>
Requirement

可选的

类型

Python expression

默认

{}

readonly

Whether the field can be modified by the user (False) or is read-only (True), as a Python expression that evaluates to a bool.

Example

<field name="fname_a" readonly="True"/>
<field name="fname_b" readonly="name_a in [fname_b, parent.fname_d]"/>
Requirement

可选的

类型

Python expression

默认

False

required

Whether the field can be left empty (False) or must be set (True), as a Python expression that evaluates to a bool.

Example

<field name="fname_a" required="True"/>
<field name="fname_b" required="fname_c != 3"/>
Requirement

可选的

类型

Python expression

默认

False

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

domain

The filters to apply when displaying existing records for selection, as a Python expression that evaluates to a domain.

Example

<field name="fname" domain="[('fname_a', '=', parent.fname_b)]"/>
Requirement

可选的

类型

Python expression

默认

[]

Scope

关联字段

context

The context to use when fetching possible values and creating or searching records, as a Python expression that evaluates to a dict.

Example

<field name="fname" context="{
    'TYPE_view_ref': 'ADDON.MODEL_view_TYPE',
    'group_by': 'FIELD_NAME',
    'default_FIELD_NAME': ANY,
    'search_default_FIELD_NAME': True,
    'OTHER_BUSINESS_KEY': ANY,
  }"/>
Requirement

可选的

类型

Python expression

默认

{}

Scope

关联字段

nolabel

Whether the field label should be hidden.

Requirement

可选的

类型

bool

默认

False

Scope

Fields that are a direct child of a group element

placeholder

The help message to display on empty fields. It can replace field labels in complex forms. However, it should not be an example of data, as users may confuse placeholder text with filled fields.

Requirement

可选的

类型

str

默认

''

mode

The comma-separated list of display modes (view types) to use for the field’s linked records. Allowed modes are: list, form, kanban, and graph.

Requirement

可选的

类型

str

默认

list

Scope

One2many and Many2many fields

class

The HTML class to set on the generated element.

The styling uses the Bootstrap framework and UI icons. Common Odoo classes include:

  • oe_inline: prevents the usual line break following fields, and limits their span;

  • oe_left, oe_right: floats the element to the corresponding direction;

  • oe_read_only, oe_edit_only: only displays the element in the corresponding form mode;

  • oe_avatar: for image fields, displays images as an “avatar” (max 90x90 square);

  • oe_stat_button: defines a particular rendering to dynamically display information while being clickable to target an action.

Example

<field name="fname" class="oe_inline oe_left oe_avatar"/>

Example

<button type="object" name="ACTION" class="oe_stat_button" icon="FONT_AWESOME" help="HELP">
   <div class="o_field_widget o_stat_info">
      <span class="o_stat_value"><FIELD/></span>
      <span class="o_stat_text">TEXT</span>
   </div>
</button>
Requirement

可选的

类型

str

默认

''

filename

The name of the related field providing the name of the file.

Requirement

可选的

类型

str

默认

''

Scope

Binary fields

password

Whether the field stores a password and thus its data should not be displayed.

Requirement

可选的

类型

bool

默认

False

Scope

Char fields

kanban_view_ref

The XMLID of the specific Kanban view record that should be used when selecting records in a mobile environment.

Requirement

可选的

类型

str

默认

''

Scope

关联字段

default_focus

Whether the field is focused when the view opens. It can be applied to only one field of a view.

Requirement

可选的

类型

bool

默认

False

注解

Relational fields nodes can contain specific subviews.

Example

<field name="children_ids">
   <list>
      <field name="name"/>
   </list>
   <form>
      <field name="id"/>
      <field name="name"/>
   </form>
</field>

label: display field labels

When a field component is not placed directly inside a group, or when its nolabel attribute is set, the field’s label is not automatically displayed alongside its value. The label component is the manual alternative of displaying the label of a field.

<form>
    <div class="col col-md-auto">
        <label for="FIELD_NAME" string="LABEL"/>
        <div>
            <field name="FIELD_NAME" class="oe_inline"/>
        </div>
    </div>
</form>

The label element can have the following attributes:

for

The reference to the field associated with the label. It can be either the name of the field, or its id (the id attribute set on the field).

When there are several occurrences of the same field in the view, and there are several label components associated with these field nodes, these labels must have unique for attribute; in this case, referencing the id attribute of the corresponding field nodes.

Requirement

强制性的

类型

str

string

The label to display.

Requirement

可选的

类型

str

默认

The field’s label coming from the field definition on the model

class

The HTML class to set on the generated element.

The styling uses the Bootstrap framework and UI icons. Common Odoo classes include:

  • oe_inline: prevents the usual line break following fields, and limits their span;

  • oe_left, oe_right: floats the element to the corresponding direction;

  • oe_read_only, oe_edit_only: only displays the element in the corresponding form mode;

  • oe_avatar: for image fields, displays images as an “avatar” (max 90x90 square);

  • oe_stat_button: defines a particular rendering to dynamically display information while being clickable to target an action.

Example

<field name="fname" class="oe_inline oe_left oe_avatar"/>

Example

<button type="object" name="ACTION" class="oe_stat_button" icon="FONT_AWESOME" help="HELP">
   <div class="o_field_widget o_stat_info">
      <span class="o_stat_value"><FIELD/></span>
      <span class="o_stat_text">TEXT</span>
   </div>
</button>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

button: display action buttons

<form>
    <button type="object" name="ACTION" string="LABEL"/>
    <button type="object" name="ACTION" icon="FONT_AWESOME"/>
</form>

The button element can have the following attributes:

type

The type of the button indicating how it behaves. It can have two different values:

object

Call a method on the view’s model. The button’s name is the method that is called with the current record ID and the current context.

action

Load and execute an ir.actions action record. The button’s name is the XMLID of the action to load. The context is extended with the view’s model (as active_model) and with the current record (as active_id).

Example

<button type="object" name="action_create_new" string="Create document"/>
<button type="action" name="addon.action_create_view" string="Create and Edit"/>
Requirement

Mandatory if the special attribute is not set

类型

str

name

The method to call if the type is object. The XMLID of the action to load if the type is action, either in raw format or in %(XMLID)d format.

Requirement

可选的

类型

str

默认

''

string

The button’s text if there is no icon, the alt text for the icon otherwise.

Example

<button type="object" name="action_create_new" string="Create document"/>
Requirement

可选的

类型

str

默认

''

icon

The icon to use to display the button. See icons for the reference list.

Example

<button type="object" name="remove" icon="fa-trash"/>
Requirement

可选的

类型

str

默认

''

help

The tooltip message shown when hovering with the mouse cursor.

Example

<button type="object" name="remove" icon="fa-trash" help="Revoke"/>
Requirement

可选的

类型

str

默认

''

context

The context that is merged into the view’s context when performing the button’s call, as a Python expression that evaluates to a dict.

Example

<button name="button_confirm" type="object" context="{'BUSINESS_KEY': ANY}" string="LABEL"/>
Requirement

可选的

类型

Python expression

默认

{}

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

class

The HTML class to set on the generated element.

The styling uses the Bootstrap framework and UI icons. Common Odoo classes include:

  • oe_inline: prevents the usual line break following fields, and limits their span;

  • oe_left, oe_right: floats the element to the corresponding direction;

  • oe_read_only, oe_edit_only: only displays the element in the corresponding form mode;

  • oe_avatar: for image fields, displays images as an “avatar” (max 90x90 square);

  • oe_stat_button: defines a particular rendering to dynamically display information while being clickable to target an action.

Example

<field name="fname" class="oe_inline oe_left oe_avatar"/>

Example

<button type="object" name="ACTION" class="oe_stat_button" icon="FONT_AWESOME" help="HELP">
   <div class="o_field_widget o_stat_info">
      <span class="o_stat_value"><FIELD/></span>
      <span class="o_stat_text">TEXT</span>
   </div>
</button>
Requirement

可选的

类型

str

默认

''

special

The behavior of the button for form views opened in dialog. It can have two different values:

save

Save the record and close the dialog.

cancel

Close the dialog without saving.

Example

<button special="cancel" icon="fa-trash"/>
Requirement

可选的

类型

str

默认

''

confirm

The confirmation message to display (and for the user to accept) before performing the button’s action.

Example

<button name="action_destroye_gate" string="Send the goa'uld" type="object" confirm="Do you confirm the action?"/>
Requirement

可选的

类型

str

默认

''

data-hotkey

The hotkey (keyboard_shortcut, similar to an accesskey) that is bound to the button. It is enabled when the alt key is pressed together with the selected character, or together with the shift key and the selected character when shift+ is prepended to the value.

Example

<button type="object" name="action_confirm" string="Confirm" data-hotkey="c"/>
<button type="object" name="action_tear" string="Tear the sheet" data-hotkey="shift+k"/>
Requirement

可选的

类型

str

默认

''

Chatter widget

The chatter widget is the communication and log tool allowing to email colleagues and customers directly from a record (task, order, invoice, event, note…).

It is added with a div element with the class oe_chatter when the model inherits the mail.thread mixin.

Example

<form>
    <sheet>
        ...
    </sheet>
    <div class="oe_chatter">
        <field name="message_follower_ids"/>
        <field name="activity_ids"/>
        <field name="message_ids" options="OPTIONS"/>
    </div>
</form>

Attachments preview widget

The attachment preview widget is added with an empty div element with the class o_attachment_preview.

Example

<form>
    <sheet>
        ...
    </sheet>
    <div class="o_attachment_preview"/>
<form>

结构组件

结构组件提供结构或“视觉”特征,具有较少的逻辑。它们用作表单视图中的元素或元素集。

Form views accept the following children structural components: group, sheet, notebook, notebook, newline, separator, header, footer, Buttons container, and Title container.

Placeholders are denoted in all caps.

group: define columns layouts

The group element is used to define column layouts in forms. By default, groups define 2 columns, and most direct children of groups take a single column.

field elements that are direct children of groups display a label by default, and the label and the field itself have a colspan of 1 each.

Children are laid out horizontally (they try to fill the next column before changing row).

 <form>
     <group>
         ...
     </group>
</form>

The group element can have the following attributes:

string

The title displayed for the group.

Requirement

可选的

类型

str

默认

''

col

The number of columns in a group.

Requirement

可选的

类型

int

默认

2

colspan

The number of columns taken by a child element.

Requirement

可选的

类型

int

默认

1

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

Possible structure and representation of its rendering

../../../_images/form_group.svg
<group>
    <field name="a" string="custom"/>
    <field name="b"/>
</group>
<group string="title 1">
    <group string="title 2">
        <field name="c"/>
        <field name="d"/>
    </group>
    <group>
        <field name="e"/>
        <field name="f"/>
        <field name="g"/>
    </group>
</group>
<group col="12">
    <group colspan="8">
        <field name="h"/>
    </group>
    <group colspan="4">
        <field name="i"/>
    </group>
</group>

sheet: make the layout responsive

The sheet element can be used as a direct child of the form root element for a narrower and more responsive form layout (centered page, margin…). It usually contains group elements.

<form>
    <sheet>
        ...
    </sheet>
</form>

notebook & page: add tabbed sections

The notebook element defines a tabbed section. Each tab is defined through a page child element.

The notebook element should not be placed within group elements.

<form>
    <notebook>
        <page string="LABEL">
            ...
        </page>
    </notebook>
</form>

The page element can have the following attributes:

string

The title of the tab.

Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

Possible structure and representation of its rendering

../../../_images/form_notebook.svg
<form>
    <notebook>
        <page string="Page1">
            ...
        </page>
        <page string="Page2">
            ...
        </page>
    </notebook>
</form>

newline: start new group rows

The newline element is used within group elements to end the current row early and immediately switch to a new row, without filling any remaining column beforehand.

<form>
    <group>
        ...
        <newline/>
        ...
    </group>
</form>

Possible structure and representation of its rendering

../../../_images/form_newline.svg
<form>
    <group string="Title 1">
        <group string="Title 1.1">...</group>
        <newline/>
        <group string="Title 1.2">...</group>
        <group string="Title 1.3">...</group>
    </group>
</form>

separator: add horizontal spacing

The separator element adds vertical spacing between elements within a group.

<form>
    ...
    <separator/>
    ...
</form>

The <separator> element can have the following attributes:

string

The title as a section title.

Requirement

可选的

类型

str

默认

''

Possible structure and representation of its rendering

../../../_images/form_separator.svg
<form>
    <group>
        <FIELD/>
        <separator string="Title 1"/>
        <FIELD/>
        <group>
            <FIELD/>
            <separator string="Title 2"/>
            <FIELD/>
        </group>
        <group>
            <FIELD/>
            <FIELD/>
        </group>
    </group>
</form>

小技巧

The separator element can be used to achieve visual separation between elements within the same inner group element while keeping them horizontally aligned.

header: display workflow buttons and a status

The header element combined with the sheet element provides a full-width location above the sheet itself generally used to display workflow button elements and a field element rendered as status widget.

<form>
    <header>
        <BUTTONS/>
    </header>
    <sheet>
        ...
    </sheet>
</form>

Example

<header>
    <button string="Reset" type="object" name="set_draft" invisible="state != 'done'"/>
    <field name="state" widget="statusbar" statusbar_visible="draft,posted" options="{'clickable': 1}"/>
</header>

Buttons container

A button elements container can be created with a div element with the class button_box.

<form>
    <div name="button_box">
        <BUTTONS/>
    </div>
<form>

Possible structure and representation of its rendering

../../../_images/form_button_box.svg
<form>
    <div name="button_box">
        <button type="edit" name="edit" icon="fa-edit" string="Button1"/>
        <button type="object" name="my_action" icon="fa-dollar">
            <field name="total_inv" widget="statinfo" string="Invoices"/>
        </button>
    </div>
<form>

Title container

A title field element container can be created with a div element with the class oe_title.

<form>
    <sheet>
        <div class="oe_title">
            <h1><FIELD/></h1>
        </div>
    </sheet>
<form>

设置

Settings views are a customization of the form view. They are used to display settings in a centralized place. They differ from generic form views in that they have a search bar and a sidebar.

Example

<app string="CRM" name="crm">
    <setting type="header" string="Foo">
        <field name="foo" title="Foo?."/>
        <button name="nameAction" type="object" string="Button"/>
    </setting>
    <block title="Title of group Bar">
        <setting help="this is bar" documentation="/applications/technical/web/settings/this_is_a_test.html">
            <field name="bar"/>
        </setting>
        <setting string="This is Big BAR" company_specific="1">
            <field name="bar"/>
        </setting>
    </block>
    <block title="Title of group Foo">
        <setting string="Personalize setting" help="this is full personalize setting">
            <div>This is a different setting</div>
        </setting>
    </block>
</app>

组件

Settings views accept the field, label and button elements of form views, as well as three additional children elements: app, block, and setting.

Placeholders are denoted in all caps.

app: declare the application

The app element is used to declare the application on the settings view. It creates an entry with the logo of the application on the sidebar of the view. It also acts as delimiter when searching.

<form>
    <app string="NAME" name="TECHNICAL_NAME">
    ...
    </app>
</form>

The app element can have the following attributes:

string

The name of the application.

Requirement

强制性的

类型

str

name

The technical name of the application (the name of the module).

Requirement

强制性的

类型

str

logo

The relative path to the logo.

Requirement

可选的

类型

path

默认

A path computed with the name attribute: /name/static/description/icon.png

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

block: declare a group of settings

The block element is used to declare a group of settings. This group can have a title and a description.

 <form>
     <app string="NAME" name="TECHNICAL_NAME">
         ...
         <block title="TITLE">
             ...
         </block>
         ...
     </app>
</form>

The block element can have the following attributes:

title

The title of the block of settings. One can search on its value.

Requirement

可选的

类型

str

默认

''

help

The description of the block of settings. One can search on its value.

Requirement

可选的

类型

str

默认

''

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

setting: declare the setting

The setting element is used to declare the setting itself.

The first field element in the setting is used as the main field. It is placed on the left panel if it is a boolean field, and on the top of the right panel otherwise. The field is also used to create the setting label if a string attribute is not defined.

The setting element can also contain additional elements (e.g., HTML). All of those elements are rendered in the right panel.

<form>
    <app string="NAME" name="TECHNICAL_NAME">
        <block title="TITLE">
            ...
            <setting string="SETTING_NAME">
                ...
                <field name="FIELD_NAME"/>
                ...
            </setting>
            ...
        </block>
    </app>
</form>

The <setting> element can have the following attributes:

type

By default, a setting is visually separated on two panels (left and right), and is used to edit a given field. By defining type="header", a special kind of setting is rendered instead. This setting is used to modify the scope of the other settings. For example, on the Website application, this setting is used to indicate to which website the other settings apply. The header setting is visually represented as a banner on top of the screen.

Requirement

可选的

类型

str

默认

''

string

The text used as the label of the setting.

Requirement

可选的

类型

str

默认

The first field’s label

title

The text used as a tooltip.

Requirement

可选的

类型

str

默认

''

help

The description of the setting. This text is displayed just below the setting label (with the class text-muted).

Requirement

可选的

类型

str

默认

''

company_dependent

Whether the setting is company-specific. If set, an icon is displayed next to the setting label.

It accepts only the value '1'.

Requirement

可选的

类型

str

默认

''

documentation

The path to the documentation on the setting. If set, a clickable icon is displayed next to the setting label. The path can be both an absolute or a relative path. In the latter case, it is relative to https://www.odoo.com/documentation/<version>.

Requirement

可选的

类型

path_

默认

''

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

列表

The root element of list views is list (the previous name was tree).

Possible structure and representation of its rendering

../../../_images/list.svg
<list>
    ...
</list>

Root attributes

Optional attributes can be added to the root element list to customize the view.

string

The view title. It is displayed only if you open an action that has no name and whose target is new (opening a dialog).

Requirement

可选的

类型

str

默认

''

create

禁用/启用视图上的记录创建。

Requirement

可选的

类型

bool

默认

True

edit

Disable/enable record edition on the view.

Requirement

可选的

类型

bool

默认

True

delete

Disable/enable record deletion on the view through the Action dropdown.

Requirement

可选的

类型

bool

默认

True

import

Disable/enable record import from data on the view.

Requirement

可选的

类型

bool

默认

True

export_xlsx

Disable/enable record export to data on the view.

Requirement

可选的

类型

bool

默认

True

editable

Make the view’s records editable in-place, and allow creating new records from a row of the list. It can have two different values:

top

New records are created from the top of the list.

bottom

New records are created from the bottom of the list.

The architecture for the inline form view is derived from the list view. Most attributes valid on a form view’s fields and buttons are thus accepted by list views, although they may not have any meaning if the list view is non-editable.

重要

This behavior is disabled if the edit attribute is set to False.

Requirement

可选的

类型

str

默认

''

multi_edit

Activate the multi-editing feature that allows updating a field to the same value for multiple records at once.

It accepts only the value '1'.

Requirement

可选的

类型

str

默认

''

open_form_view

Display a button at the end of each row to open the record in a form view.

It has no effect if the view is non-editable.

Requirement

可选的

类型

bool

默认

False

default_group_by

The name of the field on which the records should be grouped by default if no grouping is specified via the action or the current search.

Requirement

可选的

类型

str

默认

''

default_order

A comma-separated list of fields names that overrides the ordering defined on the model through the _order attribute.

To inverse the sorting order of a field, postfix it with desc, separated by a space.

Example

<list default_order="sequence,name desc">
    ...
</list>
Requirement

可选的

类型

str

默认

''

decoration-<style>

The style that should be applied to matching records’ rows, as a Python expression that evaluates to a bool.

<style> must be replaced by one of bf (bold), it (italic), info, warning, danger, muted, primary, and success.

Example

<list decoration-danger="field_qty &gt; field_limit">
    ...
</list>
Requirement

可选的

类型

Python expression

默认

False

limit

The default size of a page. It must be strictly positive.

Requirement

可选的

类型

int

默认

80 for list views, 40 for X2many lists in form views

groups_limit

The default number of groups on a page when the list view is grouped. It must be strictly positive.

Requirement

可选的

类型

int

默认

80 for list views, 40 for X2many lists in form views

expand

Whether the first level of groups should be opened by default when the list view is grouped.

警告

It may be slow, depending on the number of groups.

Requirement

可选的

类型

bool

默认

False

sample

Whether the view should be populated with a set of sample records if none are found for the current model.

These fake records have heuristics for certain field names/models. For example, a field display_name on the model res.users will be populated with sample people names, while an email field will be in the form firstname.lastname@sample.demo.

The user is unable to interact with these data, and they will be discarded as soon as an action is performed (record created, column added, etc.).

Requirement

可选的

类型

bool

默认

False

组件

List views accept the following children elements: field, button, groupby, header, control, and create.

Placeholders are denoted in all caps.

field: display field values

The field element renders (and allows editing of, possibly) a single field of all current records as a column.

Using the same field multiple times in a list view is not supported

<list>
    <field name="FIELD_NAME"/>
</list>

The field element can have the following attributes:

name

The name of the field to render.

Requirement

强制性的

类型

str

widget

The widget used to represent the field. The selected widget can change the way the field is rendered and/or the way it can be edited. It refers to a Javascript implementation (an Owl component) registered to the fields registry.

Requirement

可选的

类型

str

string

The label of the field.

Requirement

可选的

类型

str

默认

The string attribute of the model’s field

optional

Make the visibility of the field optional. The field’s column can be hidden or shown through a button on the view’s header.

It can have two different values:

show

The field is shown by default.

hide

The field is hidden by default.

Example

<field name="fname_a" optional="show"/>
<field name="fname_b" optional="hide"/>
Requirement

可选的

类型

str

readonly

Whether the field can be modified by the user (False) or is read-only (True), as a Python expression that evaluates to a bool.

Example

<field name="fname_a" readonly="True"/>
<field name="fname_b" readonly="name_a in [fname_b, parent.fname_d]"/>
Requirement

可选的

类型

Python expression

默认

False

required

Whether the field can be left empty (False) or must be set (True), as a Python expression that evaluates to a bool.

Example

<field name="fname_a" required="True"/>
<field name="fname_b" required="fname_c != 3"/>
Requirement

可选的

类型

Python expression

默认

False

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

column_invisible

Whether the column is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

Unlike invisible, it affects the entire column, and is evaluated without the subtree values.

Example

<field name="product_is_late" column_invisible="parent.has_late_products == False"/>
<button type="object" name="action_confirm" column_invisible="context.get('hide_confirm')"/>
Requirement

可选的

类型

Python expression

默认

False

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

decoration-<style>

The style that should be applied to matching records’ field, as a Python expression that evaluates to a bool.

<style> must be replaced by one of bf (bold), it (italic), info, warning, danger, muted, primary, and success.

Example

<field name="name" decoration-bf="1"/>
<field name="quantity" decoration-info="state == 'draft'"/>
Requirement

可选的

类型

Python expression

默认

False

sum, avg

The aggregate to display at the bottom of the column. The aggregation is computed on only records that are currently displayed. The aggregation operation must match the corresponding field’s aggregator.

Example

<field name="sent" sum="Total" />
<field name="clicks_ratio" avg="Average"/>
Requirement

可选的

类型

str

默认

''

width

The list view always tries to optimize the available space among columns. For some field types, this is done by enforcing a width, depending on the field type. For instance, we know exactly the number of pixels required to display a date, so we can ensure that a column for a date field doesn’t take more space than what is strictly necessary, thus leaving the extra space for the other columns. However, the framework can’t guess the adequate width for every field types. For instance, char fields can be used to encode large values, or 3-letter country codes. In the latter case, one can set the width directly in the arch (e.g. width="40px"). It represents the width (always in pixels) required to render the values inside the cells. The width of the column will then be the sum of the given value and the cells’ left and right paddings.

Requirement

可选的

类型

str

默认

''

nolabel

Whether the field’s column header should remain empty. If set, the column will not be sortable.

It accepts only the value '1'

Requirement

可选的

类型

str

默认

''

注解

When a list view is grouped, numeric fields are aggregated and displayed for each group. Also, if there are too many records in a group, a pager appears on the right of the group row. For this reason, it is a bad practice to have a numeric field in the last column when the list view is in a situation where it can be grouped. However, it does not pose a problem for X2many fields in a form view, as they cannot be grouped.

Possible structure and representation of its rendering

../../../_images/list_field.svg
<list>
    <field name="name" string="My Custom Name"/>
    <field name="amount" sum="Total"/>
    <field name="currency_id"/>
    <field name="tax_id"/>
</list>

button: display action buttons

<list>
    <button type="object" name="ACTION" string="LABEL"/>
    <button type="object" name="ACTION" icon="FONT_AWESOME"/>
</list>

The button element can have the following attributes:

type

The type of the button indicating how it behaves. It can have two different values:

object

Call a method on the view’s model. The button’s name is the method that is called with the current record ID and the current context.

action

Load and execute an ir.actions action record. The button’s name is the XMLID of the action to load. The context is extended with the view’s model (as active_model) and with the current record (as active_id).

Example

<button type="object" name="action_create_new" string="Create document"/>
<button type="action" name="addon.action_create_view" string="Create and Edit"/>
Requirement

Mandatory if the special attribute is not set

类型

str

name

The method to call if the type is object. The XMLID of the action to load if the type is action, either in raw format or in %(XMLID)d format.

Requirement

可选的

类型

str

默认

''

string

The button’s text if there is no icon, the alt text for the icon otherwise.

Example

<button type="object" name="action_create_new" string="Create document"/>
Requirement

可选的

类型

str

默认

''

icon

The icon to use to display the button. See icons for the reference list.

Example

<button type="object" name="remove" icon="fa-trash"/>
Requirement

可选的

类型

str

默认

''

help

The tooltip message shown when hovering with the mouse cursor.

Example

<button type="object" name="remove" icon="fa-trash" help="Revoke"/>
Requirement

可选的

类型

str

默认

''

context

The context that is merged into the view’s context when performing the button’s call, as a Python expression that evaluates to a dict.

Example

<button name="button_confirm" type="object" context="{'BUSINESS_KEY': ANY}" string="LABEL"/>
Requirement

可选的

类型

Python expression

默认

{}

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

column_invisible

Whether the column is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

Unlike invisible, it affects the entire column, and is evaluated without the subtree values.

Example

<field name="product_is_late" column_invisible="parent.has_late_products == False"/>
<button type="object" name="action_confirm" column_invisible="context.get('hide_confirm')"/>
Requirement

可选的

类型

Python expression

默认

False

class

The HTML class to set on the generated element.

The styling uses the Bootstrap framework and UI icons. Common Odoo classes include:

  • oe_inline: prevents the usual line break following fields, and limits their span;

  • oe_left, oe_right: floats the element to the corresponding direction;

  • oe_read_only, oe_edit_only: only displays the element in the corresponding form mode;

  • oe_avatar: for image fields, displays images as an “avatar” (max 90x90 square);

  • oe_stat_button: defines a particular rendering to dynamically display information while being clickable to target an action.

Example

<field name="fname" class="oe_inline oe_left oe_avatar"/>

Example

<button type="object" name="ACTION" class="oe_stat_button" icon="FONT_AWESOME" help="HELP">
   <div class="o_field_widget o_stat_info">
      <span class="o_stat_value"><FIELD/></span>
      <span class="o_stat_text">TEXT</span>
   </div>
</button>
Requirement

可选的

类型

str

默认

''

Possible structure and representation of its rendering

../../../_images/list_button.svg
<list>
    <field name="name"/>
    <button type="edit" name="edit" icon="fa-edit" title="Edit"/>
    <button type="object" name="my_method" string="Button1" column_invisible="context.get('hide_button')" invisible="amount &gt; 3"/>
    <field name="amount"/>
    <field name="currency_id"/>
    <field name="tax_id"/>
</list>

groupby: define group headers

The groupby element is used to define group headers with button elements when grouping records on Many2one fields. It also accepts field elements, which can be used for modifiers. These fields thus belong on the Many2one co-model. These extra fields are fetched in batch.

<list>
    ...
    <groupby name="FIELD_NAME">
        <BUTTONS/>
        <FIELDS/>
    </groupby>
</list>

The groupby element can have the following attributes:

name

The name of the a Many2one field to use as header.

A special button element with type="edit" can be defined to open the Many2one field’s form view.

Requirement

强制性的

类型

str

Possible structure and representation of its rendering

../../../_images/list_groupby.svg
<list>
    <field name="name"/>
    <field name="amount"/>
    <field name="currency"/>
    <field name="tax_id"/>

    <groupby name="partner_id">
        <button type="edit" name="edit" icon="fa-edit" title="Edit"/>
        <field name="email"/>
        <button type="object" name="my_method" string="Button1" invisible="email == 'jhon@conor.com'"/>
    </groupby>
</list>

注解

Fields inside the groupby element are used only to fetch and store the value, but they are never displayed.

header: display workflow buttons

<list>
    <header>
        <BUTTONS/>
    </header>
    ...
</list>

The header element accepts the following children elements:

button

The button element allows defining buttons in the control panel. It is the same element as the button element in list views, but it accepts one more attribute when placed inside a header element:

display

Make the button available at all time, without having to select records.

It accepts only the value always.

Example

<header>
    <button name="toDoAlways" type="object" string="Always displayed" display="always"/>
    <button name="toDoSelection" type="object" string="Displayed if selection"/>
</header>
Requirement

可选的

类型

str

默认

''

Possible structure and representation of its rendering

../../../_images/list_header.svg
<list>
    <header>
        <button type="object" name="to_draft" string="Button1" invisible="context.get('hide_button')"/>
    </header>
    <field name="name"/>
    <field name="amount"/>
    <field name="currency"/>
    <field name="tax_id"/>
</list>

control & create: add inline create buttons

The control element defines a control row that accepts create buttons. Each create button is defined through a create element.

<list>
   <control>
       <create string="LABEL"/>
       <BUTTONS/>
    </control>
    ...
</list>

The control element takes no attributes.

The create element can have the following attributes:

string

The button’s text.

Requirement

强制性的

类型

str

context

The context that is merged into the view’s context when performing the button’s call, as a Python expression that evaluates to a dict.

Requirement

可选的

类型

Python expression

默认

{}

Possible structure and representation of its rendering

../../../_images/list_control.svg
<list>
    <field name="name"/>
    <field name="amount"/>
    <field name="currency"/>
    <field name="tax_id"/>
    <control>
        <create string="Add a item"/>
        <create string="Add a section" context="{'default_type': 'section'}"/>
        <create string="Add a note" context="{'default_type': 'note'}"/>
    </control>
</list>

注解

Using the control element makes sense only if the list view is inside a One2many or Many2many field. If any create element is defined, it overwrites the default add a line button.

组件

Search views accept the following children elements: field, filter, separator, group, and searchpanel.

Placeholders are denoted in all caps.

field: filter based on field values

The field element defines domains or contexts with user-provided values. When search domains are generated, field domains are joined with each other and with filters using the AND operator.

<search>
    <field name="FIELD_NAME"/>
</search>

The field element can have the following attributes:

name

The name of the field to filter on.

Requirement

强制性的

类型

str

string

The label of the field.

Requirement

可选的

类型

str

默认

The string attribute of the model’s field

operator

By default, fields generate domains of the form [(name, operator, value)], where name is the field’s name and value is the value provided by the user, possibly filtered or transformed (e.g., a user is expected to provide the label of a selection field’s value, not the value itself).

The operator attribute allows overriding the default operator, which depends on the field’s type (e.g., = for float fields, but ilike for char fields and child_of for many2one).

Requirement

可选的

类型

str

默认

=

filter_domain

The domain to use as the field’s search domain, as a Python expression that evaluates to a domain.

It can use the self variable to inject the provided value in the custom domain. It can be used to generate significantly more flexible domains than with the operator attribute alone (e.g., search on multiple fields at once).

If both the operator and filter_domain attributes are provided, filter_domain takes precedence.

Requirement

可选的

类型

Python expression

默认

[]

context

The context to merge into the context of the view that the search view is targeting, as a Python expression that evaluates to a dict.

It can contain user-provided values, which are available under the self variable.

Requirement

可选的

类型

Python expression

默认

{}

domain

The filters to apply to the completion results for fields that allow for auto-completion (e.g., Many2one).

Requirement

可选的

类型

Python expression

默认

[]

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

Possible structure and representation of its rendering

../../../_images/search_field.svg
<search>
    <field name="name" string="My Custom Name"/>
    <field name="amount"/>
    <field name="currency_id"/>
    <field name="ref" filter_domain="[('name', 'like', self)]"/>
</search>

filter: create pre-defined filters

The filter element is used to create pre-defined filters that can be toggled in the search view. It allows adding data to the search context the context passed to the data view for searching/filtering, or appending new sections to the search filter.

<search>
    <filter string="LABEL" domain="DOMAIN"/>
</search>

The filter element can have the following attributes:

name

The technical name of the filter. It can be used to enable it by default or as an inheritance hook.

Requirement

强制性的

类型

str

string

The label of the filter.

Requirement

强制性的

类型

str

help

The tooltip displayed when hovering the filter.

Requirement

可选的

类型

str

默认

''

domain

The domain to append to the action’s domain as part of the search domain.

Requirement

可选的

类型

Python expression

默认

[]

date

The name of the date or datetime field to filter on.

When used, this attribute creates a set of filters available in a sub-menu of the Filters menu. The available filters are time-dependent but not dynamic in the sense that their domains are evaluated at the time of the control panel instantiation.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date"/>

By default, these filters contain a dropdown with different sub-filters that allow you to filter based on months, quarters and years. Additionally, you can create custom sub-filters that allow filtering using domains. These custom filters must have the following attributes: name, string and domain.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date">
   <filter name="create_date_last_30_days" string="Last 30 Days" domain="[('create_date', '&gt;', datetime.datetime.combine(context_today() - relativedelta(days=30), datetime.time(23, 59, 59)).to_utc())]"/>
</filter>

Note that all custom filters defined this way are mutually exclusive with each other and with the other sub-filters.

Requirement

可选的

类型

str

默认

''

start_month

The earliest month that will show up in the dropdown of a date filter, as an offset relative to the current month.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date" start_month="-3"/>

If the current month is February, the earliest month selectable in the dropdown will be November.

Requirement

可选的

类型

int

默认

-2

Scope

Filters with a non-empty date attribute

end_month

The latest month that will show up in the dropdown of a date filter, as an offset relative to the current month.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date" end_month="2"/>

If the current month is February, the latest month selectable in the dropdown will be March.

Requirement

可选的

类型

int

默认

0

Scope

Filters with a non-empty date attribute

start_year

The earliest year that will show up in the dropdown of a date filter, as an offset relative to the current year.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date" start_year="-3"/>

If the current year is 2024, the earliest year selectable in the dropdown will be 2021.

Requirement

可选的

类型

int

默认

-2

Scope

Filters with a non-empty date attribute

end_year

The latest year that will show up in the dropdown of a date filter, as an offset relative to the current year.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date" end_year="2"/>

If the current year is 2024, the latest year selectable in the dropdown will be 2025.

Requirement

可选的

类型

int

默认

0

Scope

Filters with a non-empty date attribute

default_period

The default period of the time-based filter (with a date attribute). It must be one of, or a comma-separated list of valid filter ids.

Valid filter ids include the following:

  • first_quarter, second_quarter, third_quarter and fourth_quarter.

  • One of month, month-x and month+x, where x is a non-zero integer value between start_month and end_month.

  • One of year, year-x and year+x, where x is a non-zero integer value between start_year and end_year.

  • The name of any custom filter defined within the filter, prepended with custom_.

The filter must be in the default set of filters activated at the view initialization.

Example

<filter string="Creation Date" name="filter_create_date" date="create_date" default_period="year,month-1"/>

Example

<filter string="Creation Date" name="filter_create_date" date="create_date" default_period="custom_create_date_last_30_days">
   <filter name="create_date_last_30_days" string="Last 30 Days" domain="[('create_date', '&gt;', datetime.datetime.combine(context_today() - relativedelta(days=30), datetime.time(23, 59, 59)).to_utc())]"/>
</filter>
Requirement

可选的

类型

str

默认

month, or the closest value to the current month if unavailable

Scope

Filters with a non-empty date attribute

invisible

Whether the element is visible (False) or hidden (True), as a Python expression that evaluates to a bool.

注解

There are two uses for the invisible attribute:

  • Usability: to avoid overloading the view and to make it easier for the user to read, depending on the content.

  • Technical: a field must be present (invisible is enough) in the view to be used in a Python expression.

Example

<field name="fname_b" invisible="fname_c != 3 and fname_a == parent.fname_d"/>
<group invisible="fname_c != 4">
    <field name="fname_c"/>
    <field name="fname_d"/>
<group>
Requirement

可选的

类型

Python expression

默认

False

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

context

The context merged into the action’s domain to generate the search domain

The context key group_by set with a field as value can be used to define a group available in the Group By menu. When the field is of type date or datetime, the filter generates a submenu of the Group By menu with the following interval options available: Year, Quarter, Month, Week, and Day. When the filter is in the default set of filters activated at the view initialization, the records are grouped by month by default. This can be changed by using the syntax date_field:interval.

Example

<filter string="Category" name="groupby_category" context="{'group_by': 'category_id'}"/>
<filter string="Creation Date" name="groupby_create_date" context="{'group_by': 'create_date:week'}"/>

注解

The results of read_groups grouped on a field may be influenced by its group_expand attribute, allowing to display empty groups when needed. For more information, please refer to Field.

Requirement

可选的

类型

Python expression

默认

{}

小心

Sequences of filters (without non-filters elements separating them) are treated as inclusively composited: they will be composed with OR rather than the usual AND.

Example

<filter domain="[('state', '=', 'draft')]"/>
<filter domain="[('state', '=', 'done')]"/>

Records whose state field is draft or done are shown.

Example

<filter domain="[('state', '=', 'draft')]"/>
<separator/>
<filter domain="[('delay', '&lt;', 15)]"/>

Records whose state field is draft and delay field is below 15.

Possible structure and representation of its rendering

../../../_images/search_filter.svg
<search>
    <filter string="My Custom Name" domain="[('name', 'ilike', 'AAA')]"/>
    <filter string="My orders" domain="[('user_id', '=', uid)]"/>
    <filter string="Category" context="{'group_by': 'category_id'}"/>
</search>

separator: separate groups of filters

The separator element is used to separates groups of filters in simple search views. For more complex search views, the group element is recommended.

<search>
    <FILTERS/>
    <separator/>
    <FILTERS/>
</search>

The separator element takes no attributes.

group: separate groups of filters

The group element is used to separate groups of filters in cluttered search views. In simpler search views, it can be substituted for the separator element.

<search>
    <group expand="0" string="LABEL">
        <FILTERS/>
    </group>
</search>

The group element takes no attributes.

searchpanel: display search panels

The searchpanel element displays a search panel to the left of multi-records views. It allows for quickly filtering data on the basis of given fields.

<search>
    <searchpanel>
        <FIELDS/>
    </searchpanel>
</search>

The searchpanel element accepts only field children elements.

The field element used as a child element of a searchpanel element can have the following attributes:

name

The name of the field to filter on.

Requirement

强制性的

类型

str

string

The label of the field.

Requirement

可选的

类型

str

默认

The string attribute of the model’s field

select

The behavior and display of the field. It can have two different values:

one

At most one value can be selected. Supported field types are many2one and selection.

multi

Several values can be selected. Supported field types are many2one, many2many and selection.

Requirement

可选的

类型

str

默认

one

groups

The comma-separated list of user groups to whom the element is displayed. Users who do not belong to at least one of these groups are unable to see the element. Groups can be prefixed with the negative ! operator to exclude them.

Example

<field name="FIELD_NAME" groups="base.group_no_one,!base.group_multi_company"/>
Requirement

可选的

类型

str

默认

''

icon

The icon of the field.

Requirement

可选的

类型

str

默认

''

color

The color of the field.

Requirement

可选的

类型

str

默认

''

When the field element has the select=one attribute set, it can have the following additional attributes:

hierarchize

Whether child categories should appear under their parent category, or at the same hierarchy level.

Requirement

可选的

类型

bool

默认

True

Scope

Many2one fields

When the field element has the select=multi attribute set, it can have the following additional attributes:

enable_counters

Whether the record counters is computed and displayed if non-zero.

小技巧

This attribute exists to avoid impacting performance. Another way to address performance issues is to override the search_panel_select_range and search_panel_select_multi_range methods.

Requirement

可选的

类型

bool

默认

False

expand

Whether categories and filters with no records should be shown.

Requirement

可选的

类型

bool

默认

False

limit

The maximal number of values to fetch for the field. If the limit is reached, no values are displayed on the search panel, and an error message is shown instead. If set to 0, all values are fetched.

Requirement

可选的

类型

int

默认

200

domain

The conditions that the records have to satisfy.

Example

<searchpanel>
    <field name="department_id"/>
    <field name="manager_id" select="multi" domain="[('department_id', '=', department_id)]"/>
</searchpanel>
Requirement

可选的

类型

Python expression

默认

[]

groupby

The name of the field name on which values should be grouped.

Requirement

可选的

类型

str

默认

''

Scope

Many2one and Many2many fields

搜索默认值

Search fields and filters can be configured through the action’s context using search_default_name keys. For fields, the value must be the value to set to the field. For filters, it must be a boolean value or a number.

Example

With foo, a field, and bar, a filter, the following action context will search foo on acro and enable bar by default:

{
    'search_default_foo': 'acro',
    'search_default_bar': 1
}

A numeric value (between 1 and 99) can be used to define the order of default groupby filters.

Example

With foo and bar, two groupby filters, the following action context will first enable bar, then foo.

{
    'search_default_foo': 2,
    'search_default_bar': 1
}

看板

Kanban views are used as a kanban board visualisation: they display records as “cards”, halfway between a list and a form view.

Records may be grouped in columns for use in workflow visualisation or manipulation (e.g., tasks or work-progress management), or ungrouped (used simply to visualize records).

The root element of Kanban views is kanban.

Possible structure and representation of its rendering

../../../_images/kanban.svg
<kanban>
    ...
</kanban>

注解

Kanban views load and display a maximum of ten columns. Any column after that is closed but can still be opened by the user.

Root attributes

Optional attributes can be added to the root element kanban to customize the view.

string

The view title. It is displayed only if you open an action that has no name and whose target is new (opening a dialog).

Requirement

可选的

类型

str

默认

''

create

禁用/启用视图上的记录创建。

Requirement

可选的

类型

bool

默认

True

edit

Disable/enable record edition on the view.

Requirement

可选的

类型

bool

默认

True

delete

Disable/enable record deletion on the view through the Action dropdown.

Requirement

可选的

类型

bool

默认

True

default_group_by

The name of the field on which the records should be grouped by default if no grouping is specified via the action or the current search.

Requirement

可选的

类型

str

默认

''

default_order

A comma-separated list of fields names that overrides the ordering defined on the model through the _order attribute.

To inverse the sorting order of a field, postfix it with desc, separated by a space.

Example

<list default_order="sequence,name desc">
    ...
</list>
Requirement

可选的

类型

str

默认

''

class

Add HTML classes to the root HTML element of the view.

Requirement

可选的

类型

str

默认

''

examples

The key in the KanbanExamplesRegistry of the examples that can be browsed when creating a new column in the grouped kanban view.

Requirement

可选的

类型

str

默认

''

group_create

Whether the Add a new column bar is visible.

Requirement

可选的

类型

bool

默认

True

group_delete

Whether columns can be deleted via the cog menu.

Requirement

可选的

类型

bool

默认

True

group_edit

Whether columns can be edited via the cog menu.

Requirement

可选的

类型

bool

默认

True

groups_draggable

Whether columns can be reordered.

Requirement

可选的

类型

bool

默认

True

records_draggable

Whether records can be dragged when the kanban view is grouped.

Requirement

可选的

类型

bool

默认

True

archivable

Whether records belonging to a column can be archived and unarchived when the active field is defined on the model.

Requirement

可选的

类型

bool

默认

True

quick_create

Whether it should be possible to create records without switching to the form view.

Requirement

可选的

类型

bool

默认

True when the kanban view is grouped by many2one, selection, char, or boolean fields, otherwise False

quick_create_view

The reference of the form view to open when using the quick creation of records.

Requirement

可选的

类型

str

默认

''

on_create

The custom action to call when clicking on Create.

If set to 'quick_create', the quick creation of records is used instead. If the quick creation is disabled, the standard create action is called.

Requirement

可选的

类型

str

默认

''

can_open

By default, clicking on a kanban card opens the corresponding record in a form view. This behavior can be disabled by setting the attribute can_open to False.

Requirement

可选的

类型

bool

默认

True

highlight_color

Name of the integer field used to color the left border of the kanban cards.

Requirement

可选的

类型

str

sample

Whether the view should be populated with a set of sample records if none are found for the current model.

These fake records have heuristics for certain field names/models. For example, a field display_name on the model res.users will be populated with sample people names, while an email field will be in the form firstname.lastname@sample.demo.

The user is unable to interact with these data, and they will be discarded as soon as an action is performed (record created, column added, etc.).

Requirement

可选的

类型

bool

默认

False

组件

Kanban views accept the following children elements: templates, field, header, progressbar.

templates: define cards structure

The templates element is used to define the QWeb templates that structure the kanban cards.

The definition of a card’s structure can be split into multiple templates for clarity, but at least one root card template must be defined.

An additional template can be defined: menu. If defined, it is rendered inside a dropdown that can be toggled with a vertical ellipsis () on the top right of the card.

The templates are written in JavaScript QWeb.

<kanban>
   <templates>
      <t t-name="card">
         <field name="name"/>
      </t>
   </templates>
</kanban>

警告

These are QWeb templates, not Owl templates, meaning that directives like t-on-click aren’t available.

字段

Inside those templates, the field element allows to render a field. It can have the following attributes:

name

The name of the field to render.

Requirement

强制性的

类型

str

widget

The widget used to represent the field. The selected widget can change the way the field is rendered and/or the way it can be edited. It refers to a Javascript implementation (an Owl component) registered to the fields registry.

Requirement

可选的

类型

str

By default, field nodes are replaced by a span containing their formatted value, unless the widget attribute is specified, in which case their rendering and behavior depends on the corresponding widget. The widget attribute can have different values including:

handle

Allows reordering records with a drag and drop, using the corresponding field as order.

kanban_color_picker

Allows editing a color (integer) field. Combined with the root attribute highlight_color, allows editing the color of the cards.

See the Field section to discover various widgets and their options.

Rendering Context

Kanban templates being rendered with the QWeb engine, they have a rendering context, a set of variables available in the templates, containing useful information and tools. Here’re the available variables:

record

An object with all the fields defined in the view. Each field has two attributes: value and raw_value. The former is formatted according to current user parameters, while the latter is the raw value (e.g. the id for a many2one field). This object is useful for instance, for using field values inside t-if conditions. For display purposes, we recommend using the <field> tag.

Example

<kanban>
   <templates>
      <field name="is_company"/>
      <t t-name="card">
         <field name="name"/>
         <field t-if="!record.is_company.raw_value" name="parent_id">
      </t>
   </templates>
</kanban>
widget

An object with 2 keys defining the available actions for the user:

  • editable: true if the user can edit records, false otherwise;

  • deletable: true if the user can delete records, false otherwise.

This is useful to conditionally display elements requiring specific access rights.

Example

<kanban>
   <templates>
      <t t-name="card">
         <field name="name"/>
      </t>
      <t t-name="menu">
         <a t-if="widget.deletable" role="menuitem" type="delete" class="dropdown-item">Delete</a>
      </t>
   </templates>
</kanban>
context

The current context propagated from either the action that opens the kanban view, or the one2many or many2many field that embeds the kanban view in a form view.

read_only_mode

Indicates that the view is readonly.

类型

bool

selection_mode

Whether the kanban view is opened when selecting a many2one or many2many field (in mobile environment).

类型

bool

luxon

The luxon object, allowing to manipulate date and datetime field values.

JSON

The Javascript JSON namespace object containing a parse method allowing to parse json field values into Javascript Objects.

小部件

The widget element allows to insert dynamically generated (in Javascript) html inside the cards. It has a mandatory name attribute, referring to a Javascript implementation (an Owl component) registered to the view_widgets registry.

See the Widget section to discover various widgets and their options.

Layouts

Several card layouts can be easily obtained using standard html elements and Bootstrap utility classes. By default, the card is a flexbox container with column direction.

Example

<kanban>
   <templates>
      <t t-name="card">
         <field class="fw-bold fs-5" name="display_name"/>
         <field class="text-muted" name="parent_id"/>
         <field name="tag_ids" widget="many2many_tags"/>
      </t>
   </templates>
</kanban>

The footer html element is styled to stick to the bottom of the card, and is as a flexbox container with row direction, allowing to easily display several fields on the same line.

Example

<kanban>
   <templates>
      <t t-name="card">
         <field class="fw-bold fs-5" name="display_name"/>
         <field class="text-muted" name="parent_id"/>
         <field name="tag_ids" widget="many2many_tags"/>
         <footer>
            <field name="priority" widget="priority"/> <!-- bottom left corner -->
            <field class="ms-auto" name="activity_ids" widget="kanban_activity"/> <!-- bottom right corner -->
         </footer>
      </t>
   </templates>
</kanban>

To display some content, like an image, on the side of the card, one can use aside and main html elements, with the flex-row classname on the card. The main node is a flexbox container like the card is when there’s no aside.

Example

<kanban>
   <templates>
      <t t-name="card" class="flex-row">
         <aside>
            <field name="avatar_128" widget="image" alt="Avatar"/>
         </aside>
         <main class="ms-2">
            <field class="fw-bold fs-5" name="display_name"/>
            <field class="text-muted" name="parent_id"/>
            <field name="tag_ids" widget="many2many_tags"/>
            <footer>
               <field name="priority" widget="priority"/>
               <field class="ms-auto" name="activity_ids" widget="kanban_activity"/>
            </footer>
         </main>
      </t>
   </templates>
</kanban>

小技巧

The classname o_kanban_aside_full set on the aside element removes the padding so that the image spreads to the borders of the card.

field: declare more fields to fetch

The field element can also be used outside the kanban templates. In that case, it allows to declare fields that are not displayed in the card, but still need to be fetched, for instance because their value is used in a t-if condition.

Example

<kanban>
   <templates>
      <field name="is_company"/>
      <t t-name="card">
         <field name="name"/>
         <field t-if="!record.is_company.raw_value" name="parent_id">
      </t>
   </templates>
</kanban>

header: display buttons in the control panel

The header element is used to insert custom buttons in the control panel.

<kanban>
   <header>
      ...
   </header>
   ...
</kanban>

The header element accepts only button children elements, similar to list views’ button elements.

The button element used as a child element of the header element can have the following additional attributes:

display

The display mode of the button. It can have two different values:

display

The button is displayed only when some records are selected; their action applies to the selected records.

always

The button is displayed at all times, even if no records are selected.

重要

Only the always display mode is available because it is not yet possible to select records in a kanban view.

Example

<header>
    <button name="toDoAlways" type="object" string="Always displayed" display="always"/>
    <button name="toDoSelection" type="object" string="Displayed if selection"/>
</header>
Requirement

可选的

类型

str

默认

display

progressbar: show progress bars on top of columns

The progressbar element is used to define a progress bar to display on top of kanban columns in grouped kanban views.

<kanban>
    <progressbar field="FIELD_NAME"/>
    ...
</kanban>

The progressbar element can have the following attributes:

field

The name of the field on which the progress bar’s sub-groups are based.

Requirement

强制性的

类型

str

colors

The mapping of the progress bar’s field values to the color values muted, success, warning, and danger.

Requirement

强制性的

类型

JSON

sum_field

The name of the field to use in a sum displayed next to the progress bar. If not set, the total number of records is displayed instead.

Requirement

可选的

类型

str

默认

''

Possible structure and representation of its rendering

../../../_images/kanban_progressbar.svg
<kanban>
    <progressbar field="activity_state"
                 colors="{'planned': 'success', 'today': 'warning', 'overdue': 'danger'}"
                 sum_field="expected_revenue"/>
    <templates>
        ...
    </templates>
</kanban>

QWeb

QWeb 视图是视图的 arch 中的标准 QWeb模板 模板。它们没有特定的根元素。因为 QWeb 视图没有特定的根元素,所以必须明确指定它们的类型(不能从 arch 字段的根元素中推断出来)。

QWeb视图有两种用途:

  • 它们可以用作前端模板,在这种情况下,应该使用 template 作为快捷方式。

  • 它们可以被用作实际的qweb视图(在操作内打开),在这种情况下,它们应该被定义为具有显式 类型 (它不能被推断)和模型的常规视图。

qweb-as-view 相对于基本的 qweb-as-template 的主要增强功能包括:

  • qweb-as-view has a special case for a <nav> element bearing the CSS class o_qweb_cp_buttons: its contents should be buttons and will be extracted and moved to the control panel’s button area, the <nav> itself will be removed, this is a work-around to control panel views not existing yet

  • qweb-as-view 渲染会在标准 qweb 渲染上下文中添加几个项目:

    model

    绑定到 qweb 视图的模型

    domain

    搜索视图提供的域

    context

    搜索视图提供的上下文

    records

    一个对 model.search(domain) 的延迟代理,如果你只想遍历记录而不执行更复杂的操作(例如分组),可以使用它

  • qweb-as-view 还提供了额外的渲染钩子:

    • _qweb_prepare_context(view_id, domain) prepares the rendering context specific to qweb-as-view

    • qweb_render_view(view_id, domain) 是客户端调用的方法,将调用上下文准备方法,最终调用 env['ir.qweb'].render()

图表

图表视图用于可视化一组记录或记录组的聚合。其根元素为 <graph> ,可以使用以下属性:

type (optional)

one of bar (default), pie and line, the type of graph to use

stacked (optional)

仅用于 bar 图表。设置为 0 以防止组内的柱形图最初被堆叠。

disable_linking (optional)

将其设置为 1 以防止将图表上的点击重定向到列表视图

order (optional)

if set, x-axis values will be sorted by default according their measure with respect to the given order (asc or desc). Only used for bar and pie charts.

string (optional)

重定向到列表视图时在面包屑中显示的字符串。

sample

Whether the view should be populated with a set of sample records if none are found for the current model.

These fake records have heuristics for certain field names/models. For example, a field display_name on the model res.users will be populated with sample people names, while an email field will be in the form firstname.lastname@sample.demo.

The user is unable to interact with these data, and they will be discarded as soon as an action is performed (record created, column added, etc.).

Requirement

可选的

类型

bool

默认

False

图表视图中唯一允许的元素是 field ,它可以具有以下属性:

name (mandatory)

视图中要使用的字段名称。如果用于分组(而不是聚合),请使用此字段。

invisible (optional)

如果为真,则该字段既不会出现在活动度量中,也不会出现在可选择的度量中。

type (optional)

如果设置为 measure,该字段将被用作分组内的聚合值,而不是分组条件。它仅适用于具有该属性的最后一个字段,但对于具有字符串属性的其他字段也很有用(见下文)。

interval (optional)

on date and datetime fields, groups by the specified interval (day, week, month, quarter or year) instead of grouping on the specific datetime (fixed second resolution) or date (fixed day resolution). Default is month.

string (optional)

仅用于具有 type="measure" 的字段。在图表视图中显示字段的名称,覆盖字段的默认 Python 字符串属性。

度量值是从模型字段自动生成的;只使用可聚合字段。这些度量值也按字段字符串的字母顺序排序。

警告

图形视图聚合是在数据库内容上执行的,非存储函数字段不能在图形视图中使用。

In Graph views, a field can have a widget attribute to dictate its format. The widget should be a field formatter, of which the most interesting are float_time, and monetary.

<field name="working_hours_close" widget="float_time"/>

透视表

透视视图用于将聚合可视化为 透视表。其根元素是 <pivot>,可以使用以下属性:

disable_linking (optional)

将其设置为 1 以删除表格单元格与列表视图的链接。

display_quantity (optional)

将其设置为 1 以默认显示数量列。

default_order (optional)

在视图中使用的默认顺序(升序或降序)的度量名称。

<pivot default_order="foo asc">
   <field name="foo" type="measure"/>
</pivot>

在透视图中,唯一允许的元素是 field ,它可以具有以下属性:

name (mandatory)

视图中要使用的字段名称。如果用于分组(而不是聚合),请使用此字段。

string (optional)

将用于在数据透视表视图中显示字段的名称,覆盖字段的默认 Python 字符串属性。

type (optional)

指示该字段应该作为分组标准还是在组内作为聚合值使用。可能的值为:

row (default)

按指定字段分组,每个组都有自己的行。

col

创建列分组

measure

在分组内聚合的字段

interval

on date and datetime fields, groups by the specified interval (day, week, month, quarter or year) instead of grouping on the specific datetime (fixed second resolution) or date (fixed day resolution).

invisible (optional)

如果为真,则该字段既不会出现在活动度量中,也不会出现在可选择的度量中(对于不适合聚合的字段非常有用,例如不同单位的字段,例如 € 和 $)。

sample

Whether the view should be populated with a set of sample records if none are found for the current model.

These fake records have heuristics for certain field names/models. For example, a field display_name on the model res.users will be populated with sample people names, while an email field will be in the form firstname.lastname@sample.demo.

The user is unable to interact with these data, and they will be discarded as soon as an action is performed (record created, column added, etc.).

Requirement

可选的

类型

bool

默认

False

度量值是从模型字段自动生成的;只使用可聚合字段。这些度量值也按字段字符串的字母顺序排序。

警告

与图形视图一样,数据透视表在数据库内容上聚合数据,这意味着非存储函数字段不能在数据透视表视图中使用。

在透视视图中, field 可以有一个 widget 属性来指定其格式。该小部件应该是一个字段格式化程序,其中最有趣的是 datedatetimefloat_timemonetary

例如,可以将时间表透视图定义为:

<pivot string="Timesheet">
    <field name="employee_id" type="row"/>
    <field name="date" interval="month" type="col"/>
    <field name="unit_amount" type="measure" widget="float_time"/>
</pivot>

日历

日历视图将记录显示为每日、每周、每月或每年的事件。

注解

默认情况下,日历视图将以当前日期(今天)为中心。您可以将特定的初始日期传递给操作的上下文,以便将日历的初始焦点设置在围绕此日期的期间(参见 mode)(使用的上下文键为 initial_date

它们的根元素是 <calendar>。日历视图上可用的属性有:

字符串

string (default: '')

This view title is displayed only if you open an action that has no name and whose target is ‘new’ (opening a dialog)

创建

bool (default: True)

禁用/启用视图上的记录创建。

编辑

bool (default: True)

Disable/enable record edition on the view.

删除

bool (default: True)

通过 操作 下拉菜单禁用/启用视图上的记录删除。

date_start (required)

记录中保存事件开始日期的字段名称

date_stop

如果提供了 date_stop ,则记录的字段名称将包含事件的结束日期,记录将可以通过拖放直接在日历中移动

date_delay

替代 date_stop,提供事件的持续时间而不是其结束日期(单位:天)

color

用于 颜色分段 的记录字段名称。在日历中,同一颜色分段的记录被分配相同的高亮颜色,颜色被半随机分配。在侧边栏中显示可见记录的display_name/avatar

form_view_id

在用户创建或编辑事件时打开的视图。请注意,如果未设置此属性,则日历视图将回退到当前操作中表单视图的ID(如果有)。

event_open_popup

如果选项 ‘event_open_popup’ 设置为 true,则日历视图将在 FormViewDialog 中打开事件(或记录)。否则,它将在新的表单视图中打开事件(使用 do_action)。

quick_create

在点击时启用快速事件创建:只要求用户提供 name``(可以通过 ``rec_name 控制保存该值的字段),然后尝试仅使用该值和点击的事件时间创建新事件。如果快速创建失败,则回退到完整的表单对话框

quick_create_view_id

View to open when the attribute quick_create is set and the user creates an event instead of the default dialog.

create_name_field

记录的字段名称,保存记录的文本表示形式,用于通过“快速创建”机制创建记录时使用

all_day

记录中一个布尔字段的名称,指示相应的事件是否被标记为全天事件(持续时间无关紧要)

mode

加载日历时的默认显示模式。可能的属性有: day , week , month , year

scales

提供的比例尺的逗号分隔列表。默认情况下,所有比例尺都可用。有关可能的比例尺值,请参见模式。

create, delete

允许通过将相应的属性设置为 false 来在视图中禁用相应的操作

<field>

声明要聚合或在看板 逻辑 中使用的字段。如果字段仅在日历卡片中显示。

字段可以有额外的属性:

invisible

在卡片中隐藏该值,请使用“True”

avatar_field

仅适用于x2many字段,在卡片中显示头像而不是显示名称

write_modelwrite_fieldfilter_field

您可以添加筛选器并将结果保存在定义的模型中,筛选器将添加在侧边栏中。 filter_field 是可选的,允许您指定将保存筛选器状态的字段。

filterscolor

使用”True”将此字段添加到侧边栏的筛选器中。您可以指定一个 color 字段用于给复选框上色。

通用模型

Model._date_name = 'date'

field to use for default calendar view

活动

The Activity view is used to display the activities linked to the records. The data are displayed in a chart with the records forming the rows and the activity types the columns. The first cell of each row displays a (customizable, see templates, quite similarly to 看板) card representing the corresponding record. When clicking on others cells, a detailed description of all activities of the same type for the record is displayed.

警告

只有在安装了 mail 模块并且继承自 mail.activity.mixin 的模型中,才能使用活动视图。

活动视图的根元素是 <activity>,它接受以下属性:

string (mandatory)

一个描述视图的标题

视图元素的可能子元素有:

field

声明在活动 逻辑 中使用的字段。如果字段仅在活动视图中显示,不需要预先声明。

可能的属性有:

name (required)

要获取的字段的名称

templates

定义了 QWeb模板 模板。卡片定义可以分成多个模板以增加清晰度,但是活动视图 必须 定义至少一个根模板 activity-box,该模板将为每个记录渲染一次。

The activity view uses mostly-standard javascript qweb and provides the following context variables (see 看板 for more details):

widget

当前的 ActivityRecord(),可以用于获取一些元信息。这些方法也可以直接在模板上下文中使用,无需通过 widget 访问。

record

一个对象,其属性是所有请求的字段。每个字段都有两个属性 valueraw_value

同期

Enterprise feature

群体视图用于显示和理解一些数据随时间变化的方式。例如,假设对于某个企业,客户可以订阅某些服务。然后,群体视图可以显示每个月的订阅总数,并研究客户离开服务的速率(流失率)。单击单元格时,群体视图将重定向您到一个新的操作,您将只看到单元格时间间隔内包含的记录;此操作包含列表视图和表单视图。

注解

默认情况下,同一列表和表单视图将在动作上定义。您可以将列表视图和表单视图传递给动作的上下文,以设置/覆盖将使用的视图(使用的上下文键为 form_view_idlist_view_id

例如,这里是一个非常简单的同期视图:

<cohort string="Subscription" date_start="date_start" date_stop="date" interval="month"/>

Cohort视图的根元素是<cohort>,它接受以下属性:

string (mandatory)

一个描述视图的标题

date_start (mandatory)

一个有效的日期或日期时间字段。该字段被视图理解为记录的开始日期。

date_stop (mandatory)

一个有效的日期或日期时间字段。该字段被视图理解为记录的结束日期。这是确定流失的字段。

disable_linking (optional)

Set to 1 to prevent from redirecting clicks on cohort cells to list view.

mode (optional)

一个描述模式的字符串。它应该是’churn’或’retention’(默认)。Churn模式将从0%开始随着时间的推移而累积,而retention模式将从100%开始随着时间的推移而减少。

timeline (optional)

一个描述时间轴的字符串。它应该是’backward’或’forward’(默认)。前向时间轴将显示从date_start到date_stop的数据,而后向时间轴将显示从date_stop到date_start的数据(当date_start在未来/大于date_stop时)。

interval (optional)

描述时间间隔的字符串。它应该是 ‘day’,’week’,’month’(默认)或 ‘year’。

measure (optional)

可聚合的字段。该字段将用于计算每个单元格的值。如果未设置,则队列视图将计算出现次数。

<field> (optional)

允许指定特定字段以便从可用的度量中进行管理,其主要用途是隐藏可选度量中的字段:

name (mandatory)

在视图中使用的字段名称。

string (optional)

将在队列视图中显示该字段的名称,覆盖字段的默认 Python 字符串属性。

invisible (optional)

if true, the field will not appear either in the active measures nor in the selectable measures (useful for fields that do not make sense aggregated, such as fields in different units, e.g. € and $). If the value is a domain, the domain is evaluated in the context of the current row’s record, if True the corresponding attribute is set on the cell.

widget (optional)

alternate representations for a field’s display.

odoo.addons.base.models.ir_ui_view.sample

Whether the view should be populated with a set of sample records if none are found for the current model.

These fake records have heuristics for certain field names/models. For example, a field display_name on the model res.users will be populated with sample people names, while an email field will be in the form firstname.lastname@sample.demo.

The user is unable to interact with these data, and they will be discarded as soon as an action is performed (record created, column added, etc.).

Requirement

可选的

类型

bool

默认

False

网格

Enterprise feature

限制

此视图正在进行中,可能需要扩展或更改。

  • 只有 date 列字段已经测试过, selectionmany2one 名义上已经实现和支持,但尚未测试, datetime 根本没有实现。

  • 列单元格几乎不可配置且必须为数字

  • 单元格调整默认情况下被禁用,必须配置为启用

  • create, editdelete ACL 元数据不会自动设置在视图根上,因为在 fields_view_get 后处理中存在限制(有一个固定的显式列表来获取这些属性的视图类型)

模式

网格视图在此模块中具有自己的架构和额外的验证。视图架构如下:

<grid> (1)

架构根元素

  • 必填的 string 属性

  • 可选的 createeditdelete 属性

  • 可选的 adjustmentadjust_name 属性

    adjustment can be either object or action to indicate whether a cell’s adjustment should be performed through a method call or an action execution. adjust_name provides respectively the method name and the action id.

    在这两种情况下,调整参数都作为 grid_adjust 上下文成员提供,在 object 情况下,参数也作为位置函数参数提供(紧挨着一个空的 id 列表):

    row_domain

    匹配已调整单元格整行的域

    column_field

    调整单元格的列名称

    column_value

    已调整单元格的列的值

    cell_field

    已调整单元格的度量字段

    change

    单元格旧值和调整后值之间的差异可能为正或负

  • 可选的 hide_line_totalhide_column_total 属性

    hide_line_total

    设置为 true 以隐藏总行(默认为 false)

    hide_column_total

    设置为 true 以隐藏总计列(默认为 false)

  • 可选的 barchart_total 属性

    barchart_total

    设置为 true 以在网格底部显示基于列总计的条形图(默认为false)。

  • 可选的 create_inlinedisplay_empty 属性

    create_inline

    设置为 true 以在网格底部显示一个额外的行,带有一个 Add a line 按钮(默认为 false)。当此选项设置为 true 时,控制面板中的 Add a line 按钮将被隐藏。当没有可用数据且未设置 display_empty``(即显示帮助内容时),控制面板中的 ``Add a line 按钮将显示,以便让用户创建第一条记录。

    display_empty

    设置为 true 以在没有数据时继续显示网格(默认为false)。当您希望用户能够跟踪当前时间段(因为日期显示在列标题中)时,这可能很有用。提醒一下,当没有数据存在且未设置此属性时,将显示帮助内容而不是网格。

<button> (0+)

在视图标题中显示的常规Odoo操作按钮

  • 必填的 string 属性(按钮标签)

  • 必填的 type 属性,可以是 objectaction

    注解

    不支持工作流按钮

  • 必填的 name 属性,可以是要调用的方法的名称,也可以是要执行的操作的 ID

  • 可选的 context

The server callback is provided with all the record ids displayed in the view, either as the ids passed to the method (object button) or as the context’s active_ids (action buttons)

<field type="row"> (1+)

行分组字段,如果有的话,将被搜索视图的 groupby 过滤器替换。

在视图中, row 字段的顺序决定了它们的分组深度:如果第一个字段是 school ,第二个字段是 age ,那么记录将首先按 school 分组,然后在每个学校内按 age 分组。

<field type="col"> (1)

列分组字段。

col字段可以包含0个或多个 <range> 元素,用于指定可自定义的列范围。 range 元素具有以下强制属性

name

可以通过 grid_range 上下文值来覆盖默认范围(默认情况下为第一个)

string

范围按钮的标签(用户可见)

span

在视图中一次显示的所有列的跨度的符号名称,可能会触发分页。

对于 date 字段,有效的时间跨度目前有 weekmonth

step

前一列和后一列之间的步骤的符号名称

对于 date 字段,目前唯一有效的跨度是 day

<field type="measure"> (1)

Cell field, automatically accumulated (by read_group).

测量字段可以使用 widget 属性来自定义其显示。

服务器交互

除了可选按钮外,网格视图目前调用两个方法:

  • read_grid (provided on all models by the module) returns almost the entirety of the grid’s content as a dict:

    • 行标题是一个带有以下键的字典列表:

      values (required)

      this maps to a dictionary with a key per row field, the values are always of the form [value, label].

      domain (required)

      在单元格调整期间需要复制记录时,此行源记录的域

    • 列标题是一个至少包含一个键的字典列表:

      values (required)

      查看行标题值

      domain (required)

      查看列域值

      current (optional)

      布尔值,标记/突出显示一列

    • 将网格数据作为单元格字典的列表(行的列表)的列表返回,每个单元格字典都具有以下键:

      value

      与单元格相关联的数值

      domain

      匹配单元格记录的域(应被视为不透明)

      size

      单元格中分组的记录数

      readonly (optional)

      一个布尔值,指示此特定单元格不应该在客户端进行编辑

      classes (optional)

      一个字符串列表,包含要添加到单元格容器中(在单元格的 TD 和可编辑元素之间)的类。

      在这个列表和基类(以 o_grid_cell_ 为前缀)之间发生冲突时,将忽略此列表中的类。

      请注意,网格数据是 密集的 ,如果查询数据库时没有匹配到任何组与单元格匹配,则会生成一个带有默认值的”空”单元格,以满足必需键。

    • prevnext 可以是 falsy(无分页)或者是一个上下文项,用于合并到视图自身的上下文中,以便于 read_grid 读取上一页或下一页,应该假设它是不透明的

  • read_grid_domain(field, range) (provided on al models by the module) returns the domain matching the current configured “span” of the grid. This is also done internally by read_grid, but can be useful or necessary to call independently to use with separate e.g. search_count or read_group.

  • adjust_grid, for which there currently isn’t a blanket implementation and whose semantics are likely to evolve with time and use cases

服务器钩子

read_grid calls a number of hooks allowing the customisation of its operations from within without having to override the entire method:

_grid_format_cell(group, cell_field)

将 read_group(按组分组)的输出转换为上述格式的单元格(作为“网格数据”的一部分)

_grid_make_empty_cell(row_domain, column_domain, view_domain)

生成一个空的单元格版本(如果没有相应的组)

_grid_column_info(name, range)

基于列类型生成 ColumnMetadata 对象,存储值,可以直接返回(作为 read_grid 的一部分)或用于查询和将 read_group 重新格式化为 read_grid

grouping

用于列的实际分组字段/查询

domain

如果列字段进行分页,则在 read_group 中应用的域,可以是空列表

prevnext

在当前页面之前和之后,将被发送到 read_grid 的上下文段。如果为 False,则禁用该方向的分页

values

在“当前页面”上显示的列值,每个值都是一个带有以下键的字典:

values

将字段名称映射到整个列的值的字典,通常只有 name -> 值

domain

匹配此特定列的域

is_current

True if the current column should be specifically outlined in the grid, False otherwise

format

如何将该列/类型的值从 read_group 格式转换为 read_grid 格式(与 ColumnInfo 中的 values 匹配)

访问控制列表

  • 如果视图不可编辑,则单个单元格也不可编辑

  • if the view is not creatable, the Add a Line button will not be displayed (it currently creates a new empty record)

上下文键

grid_range

选择默认使用哪个范围,如果视图有多个范围

grid_anchor

如果适用,将用作列范围的默认锚点,而不是 read_grid 定义的默认值。

对于日期字段,计算初始跨度的参考日期。默认日期锚定为“今天”(用户所在时区)

甘特图

Enterprise feature

甘特图视图适当地显示甘特图(用于调度)。

gantt 视图的根元素是 <gantt/>,它没有子元素,但可以使用以下属性:

字符串

string (default: '')

This view title is displayed only if you open an action that has no name and whose target is ‘new’ (opening a dialog)

创建

bool (default: True)

禁用/启用视图上的记录创建。

编辑

bool (default: True)

Disable/enable record edition on the view.

删除

bool (default: True)

通过 操作 下拉菜单禁用/启用视图上的记录删除。

date_start (required)

每条记录提供事件开始日期时间的字段名称。

date_stop (required)

为每个记录提供事件结束时间的字段名称。

dependency_field

提供两个记录之间依赖关系的 many2many 字段的名称。如果B依赖于A,则 dependency_field 是允许从B获取A的字段。这个字段和 dependency_inverted_field 字段都用于绘制依赖箭头,以便调整它们的时间表。

dependency_inverted_field (required if dependency_field is provided)

提供反向依赖关系的 many2many 字段的名称比 dependency_field 更倾向于。如果B依赖于A, dependency_inverted_field 是允许从A获取B的字段。

color

用于根据其值着色药丸的字段名称

decoration-{$name}

python expression that evaluates to a bool

允许根据相应记录的属性更改单元格文本的样式。

{$name} 可以是以下 bootstrap contextual color (danger, info, secondary, successwarning)。

根据相应记录的属性,定义类似于行文本的记录的条件显示。

值是Python表达式。对于每个记录,表达式将使用记录的属性作为上下文值进行评估,如果为 true ,则将应用相应的样式到行中。以下是上下文中其他可用的值:

  • uid: the id of the current user,

  • today: the current local date as a string of the form YYYY-MM-DD,

  • now: same as today with the addition of the current time. This value is formatted as YYYY-MM-DD hh:mm:ss.

<gantt decoration-info="state == 'draft'"
      decoration-danger="state == 'help_needed'"
      decoration-bf="state == 'busy'">
  ...
</gantt>
default_group_by

按字段分组任务的字段名称

disable_drag_drop

如果设置为 true,则甘特图视图将不支持拖放操作

consolidation

在记录单元格中显示合并值的字段名称

consolidation_max

将“group by”字段作为键,最大合并值达到显示红色单元格之前的字典(例如 {"user_id": 100}

consolidation_exclude

描述任务是否需要从合并中排除的字段名称,如果设置为true,则在合并行中显示带条纹的区域

create, cell_create, edit, delete, plan

允许通过将相应的属性设置为 false (默认值: true )来 禁用 视图中的相应操作。

  • create: If enabled, an Add button will be available in the control panel to create records.

  • cell_create: If enabled and create enabled, a “+” button will be displayed while hovering on a time slot cell to create a new record on that slot.

  • edit: If enabled, the opened records will be in edit mode (thus editable).

  • plan: If enabled and edit enabled, a “magnifying glass” button will be displayed on time slots to plan unassigned records into that time slot.

Example

当您不想在甘特视图上创建记录,并且模型需要开始和结束日期时,应禁用计划功能,因为永远找不到记录。

offset

根据规模,添加到今天以计算默认周期的单位数。例如:在默认规模为周的情况下,偏移量为+1将打开下周的甘特图视图,在默认规模为月的情况下,偏移量为-2将打开2个月前的甘特图视图。

progress

记录事件完成百分比的字段名称,介于0和100之间

string

甘特图视图的标题

precision

JSON 对象,指定每个刻度中药丸的捕捉精度。

可用的刻度值为 day (默认值: hour ):

  • hour: records times snap to full hours (ex: 7:12 becomes 8:00)

  • hour:half: records times snap to half hours (ex: 7:12 becomes 7:30)

  • hour:quarter: records times snap to half hours (ex: 7:12 becomes 7:15)

Possible values for scale week are (default: day:half):

  • day: records times snap to full days (ex: 7:28 AM becomes 11:59:59 PM of the previous day, 10:32 PM becomes 12:00 PM of the current day)

  • day:half: records times snap to half hours (ex: 7:28 AM becomes 12:00 PM)

可用的刻度值为 month (默认值: day:half ):

  • day: records times snap to full days (ex: 7:28 AM becomes 11:59:59 PM of the previous day, 10:32 PM becomes 12:00 PM of the current day)

  • day:half: records times snap to half hours (ex: 7:28 AM becomes 12:00 PM)

Scale year always snap to full day.

精度属性的示例: {"day": "hour:quarter", "week": "day:half", "month": "day"}

total_row

布尔值,用于控制是否显示包含记录总数的行。(默认值: false

collapse_first_level

布尔值,用于控制是否可以折叠每一行,如果按一个字段分组。(默认值: false ,当按两个字段分组时开始折叠)

display_unavailability

boolean 用于标记模型的 gantt_unavailability 函数返回的日期在甘特图视图中是否可用。记录仍然可以在其中安排,但它们的不可用性会在视觉上显示出来。(默认值: false

default_scale

渲染视图时的默认比例。可能的值为(默认值: month ):

  • day

  • week

  • month

  • year

scales

逗号分隔的允许此视图的比例列表。默认情况下,允许所有比例。要在此列表中使用的可能比例值,请参见 default_scale

templates

定义了 QWeb模板 模板 gantt-popover,当用户悬停在甘特图视图中的记录之一时使用。

gantt视图主要使用标准的 javascript qweb 并提供以下上下文变量:

widget

the current GanttRow(), can be used to fetch some meta-information. The getColor method to convert in a color integer is also available directly in the template context without using widget.

on_create

如果在视图上点击添加按钮时指定了此参数,则不会打开通用对话框,而是启动一个客户端操作。此参数应该包含操作的xmlid(例如: on_create="%(my_module.my_wizard)d"

form_view_id

在用户创建或编辑记录时打开的视图。请注意,如果未设置此属性,则甘特图视图将回退到当前操作中表单视图的ID(如果有)。

dynamic_range

如果设置为 true,则甘特图视图将从第一条记录开始,而不是从年/月/日的开始处开始。

pill_label

如果设置为true,则在将刻度设置为周或月时,时间将显示在药丸标签中。 (例如 7:00 AM - 11:00 AM (4h) - DST Task 1)

thumbnails

如果组是关系字段,这将允许在组名旁边显示缩略图。这需要一个Python字典,其键是活动模型上字段的名称。值是相关模型上持有缩略图的字段的名称。

例如:任务有一个字段 user_id,它引用了 res.users。res.users 模型有一个字段 image,它保存了头像,那么:

<gantt
   date_start="date_start"
   date_stop="date_stop"
   thumbnails="{'user_id': 'image_128'}"
 >
 </gantt>

将按用户ID分组时,显示用户头像在其名称旁边。

odoo.addons.base.models.ir_ui_view.sample

Whether the view should be populated with a set of sample records if none are found for the current model.

These fake records have heuristics for certain field names/models. For example, a field display_name on the model res.users will be populated with sample people names, while an email field will be in the form firstname.lastname@sample.demo.

The user is unable to interact with these data, and they will be discarded as soon as an action is performed (record created, column added, etc.).

Requirement

可选的

类型

bool

默认

False

地图

Enterprise feature

此视图能够在地图上显示记录和它们之间的路线。记录由图钉表示。它还允许在与记录图钉相关联的弹出窗口中可视化模型中的字段。

注解

应用视图的模型应该包含一个 res.partner many2one,因为视图依赖于 res.partner 的地址和坐标字段来定位记录。

API

视图使用位置数据平台的API来获取瓦片(地图的背景),进行地理转发(将地址转换为一组坐标)和获取路线。视图实现了两个API,OpenStreetMap和MapBox。默认情况下使用OpenStreetMap,能够获取 瓦片 和进行 地理转发。该API不需要令牌。只要在常规设置中提供了有效的 MapBox 令牌,视图就会切换到MapBox API。该API更快,并允许计算路线。可以通过 注册 MapBox 来获取令牌。

结构组件

视图的根元素是 <map>。它可以具有以下属性:

res_partner

包含 res.partner 的 many2one 字段。如果未提供,则视图将创建一个空地图。

default_order

如果提供了字段,则视图将覆盖模型的默认排序。字段必须是应用视图的模型的一部分,而不是来自 res.partner

routing

如果为 1 ,则显示记录之间的路线。视图需要有效的 MapBox 令牌和至少两个已定位的记录(即记录具有 res.partner many2one 并且合作伙伴具有地址或有效坐标)。

hide_name

如果 1 隐藏名称在弹出窗口的针(默认: 0 )。

hide_address

如果 1 隐藏地址从弹出窗口的图钉 (默认: 0)。

hide_title

如果 1 从固定列表中隐藏标题(默认值: 0 )。

panel_title

在固定列表中显示的标题字符串。如果未提供,则标题为操作的名称或如果视图不在操作中,则为“Items”。

limit

Maximum number of records to fetch (default: 80). It must be a positive integer.

The <map> element can contain multiple <field> elements. Each <field> element is interpreted as a line in the pin’s popup. The field’s attributes are the following:

name

要显示的字段。

string

字段内容前要显示的字符串。它可以用作描述。

例如,这里是一张地图:
<map res_partner="partner_id" default_order="date_begin" routing="1" hide_name="1">
    <field name="partner_id" string="Customer Name"/>
</map>