--- custom-css: showcase_tables.css --- # 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 {file}`\*.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. :::{note} The current context and user access rights may impact the view abilities. ::: :::{seealso} {doc}`view_records` ::: (reference-view-architectures-python-expression)= ## Python expression 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 {ref}`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 {ref}`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. ```{eval-rst} .. example:: .. code-block:: xml ``` ```{eval-rst} .. example:: .. code-block:: xml
``` (reference-view-architectures-form)= ## Form 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`. ```xml
...
``` (reference-view-architectures-form-root)= ### Root attributes Optional attributes can be added to the root element `form` to customize the view. ```{eval-rst} .. include:: view_architectures/root_attribute_string.md ``` ```{eval-rst} .. include:: view_architectures/root_attribute_create.md ``` ```{eval-rst} .. include:: view_architectures/root_attribute_edit.md ``` ```{eval-rst} .. attribute:: duplicate :noindex: Disable/enable record duplication on the view through the **Action** dropdown. :requirement: Optional :type: bool :default: `True` ``` ```{eval-rst} .. include:: view_architectures/root_attribute_delete.md ``` ```{eval-rst} .. attribute:: js_class :noindex: The name of the JavaScript component the webclient will instantiate instead of the form view. :requirement: Optional :type: str :default: `''` ``` ```{eval-rst} .. attribute:: disable_autofocus :noindex: Disable automatic focusing on the first field in the view. :requirement: Optional :type: bool :default: `False` ``` (reference-view-architectures-form-semantic)= ### Semantic components Semantic components tie into the Odoo system and allow interaction with it. Form views accept the following children semantic components: {ref}`field `, {ref}`label `, {ref}`button `, {ref}`reference/view_architectures/form/chatter`, and {ref}`reference/view_architectures/form/attachment`. Placeholders are denoted in all caps. (reference-view-architectures-form-field)= #### `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. ```xml
``` The `field` element can have the following attributes: ```{eval-rst} .. include:: view_architectures/field_attribute_name.md ``` ```{eval-rst} .. attribute:: id :noindex: The node id. Useful when there are several occurrences of the same field in the view (see :ref:`reference/view_architectures/form/label`). :requirement: Optional :type: str :default: The field name ``` ```{eval-rst} .. include:: view_architectures/field_attribute_string.md ``` ```{eval-rst} .. attribute:: help :noindex: The tooltip displayed when hovering the field or its label. :requirement: Optional :type: str :default: `''` ``` ```{eval-rst} .. attribute:: options :noindex: 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:: .. code-block:: xml :requirement: Optional :type: :ref:`Python expression ` :default: `{}` ``` ```{eval-rst} .. include:: view_architectures/field_attribute_readonly.md ``` ```{eval-rst} .. include:: view_architectures/field_attribute_required.md ``` ```{eval-rst} .. include:: view_architectures/generic_attribute_invisible.md ``` ```{eval-rst} .. include:: view_architectures/generic_attribute_groups.md ``` ```{eval-rst} .. attribute:: domain :noindex: The filters to apply when displaying existing records for selection, as a Python expression that evaluates to a :ref:`domain `. .. example:: .. code-block:: xml :requirement: Optional :type: :ref:`Python expression ` :default: `[]` :scope: Relational fields ``` ```{eval-rst} .. attribute:: context :noindex: .. todo:: extensive documentation on all the magic context values (TYPE_view_ref, group_by, search_default_FIELD... The context to use when fetching possible values and creating or searching records, as a Python expression that evaluates to a dict. .. example:: .. code-block:: xml :requirement: Optional :type: :ref:`Python expression ` :default: `{}` :scope: Relational fields ``` ```{eval-rst} .. attribute:: nolabel :noindex: Whether the field label should be hidden. :requirement: Optional :type: bool :default: `False` :scope: Fields that are a direct child of a `group` element ``` ```{eval-rst} .. attribute:: placeholder :noindex: 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: Optional :type: str :default: `''` ``` ```{eval-rst} .. attribute:: mode :noindex: 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: Optional :type: str :default: `list` :scope: :class:`~odoo.fields.One2many` and :class:`~odoo.fields.Many2many` fields ``` ```{eval-rst} .. include:: view_architectures/generic_attribute_class.md ``` ```{eval-rst} .. attribute:: filename :noindex: The name of the related field providing the name of the file. :requirement: Optional :type: str :default: `''` :scope: :class:`~odoo.fields.Binary` fields ``` ```{eval-rst} .. attribute:: password :noindex: Whether the field stores a password and thus its data should not be displayed. :requirement: Optional :type: bool :default: `False` :scope: :class:`~odoo.fields.Char` fields ``` ```{eval-rst} .. attribute:: kanban_view_ref :noindex: The XMLID of the specific Kanban :doc:`view record ` that should be used when selecting records in a mobile environment. :requirement: Optional :type: str :default: `''` :scope: Relational fields ``` ```{eval-rst} .. attribute:: default_focus :noindex: Whether the field is focused when the view opens. It can be applied to only one field of a view. :requirement: Optional :type: bool :default: `False` ``` :::{note} {ref}`Relational fields ` nodes can contain specific subviews. ```{eval-rst} .. example:: .. code-block:: xml
``` ::: (reference-view-architectures-form-label)= #### `label`: display field labels When a {ref}`field ` component is not placed directly inside a {ref}`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. ```xml
``` The `label` element can have the following attributes: ```{eval-rst} .. attribute:: for :noindex: 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 :ref:`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: Mandatory :type: str ``` ```{eval-rst} .. attribute:: string :noindex: The label to display. :requirement: Optional :type: str :default: The field's label coming from the field definition on the model ``` ```{eval-rst} .. include:: view_architectures/generic_attribute_class.md ``` ```{eval-rst} .. include:: view_architectures/generic_attribute_invisible.md ``` (reference-view-architectures-form-button)= #### `button`: display action buttons ```xml
``` ::: (reference-view-architectures-form-title-container)= #### Title container A title {ref}`field ` element container can be created with a `div` element with the class `oe_title`. ```xml

``` (reference-view-architectures-settings)= ## Settings Settings views are a customization of the {ref}`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. ```{eval-rst} .. example:: .. code-block:: xml