: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. .. example:: .. code-block:: xml .. 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`. .. code-block:: xml
...
.. _reference/view_architectures/form/root: Root attributes --------------- Optional attributes can be added to the root element `form` to customize the view. .. include:: view_architectures/root_attribute_string.rst .. include:: view_architectures/root_attribute_create.rst .. include:: view_architectures/root_attribute_edit.rst .. attribute:: duplicate :noindex: Disable/enable record duplication on the view through the **Action** dropdown. :requirement: Optional :type: bool :default: `True` .. include:: view_architectures/root_attribute_delete.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: `''` .. 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. .. code-block:: xml
The `field` element can have the following attributes: .. include:: view_architectures/field_attribute_name.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 .. include:: view_architectures/field_attribute_string.rst .. attribute:: help :noindex: The tooltip displayed when hovering the field or its label. :requirement: Optional :type: str :default: `''` .. 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: `{}` .. include:: view_architectures/field_attribute_readonly.rst .. include:: view_architectures/field_attribute_required.rst .. include:: view_architectures/generic_attribute_invisible.rst .. include:: view_architectures/generic_attribute_groups.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 .. 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 .. 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 .. 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: `''` .. 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 .. include:: view_architectures/generic_attribute_class.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 .. 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 .. 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 .. 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. .. 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. .. code-block:: xml
The `label` element can have the following attributes: .. 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 .. attribute:: string :noindex: The label to display. :requirement: Optional :type: str :default: The field's label coming from the field definition on the model .. include:: view_architectures/generic_attribute_class.rst .. include:: view_architectures/generic_attribute_invisible.rst .. _reference/view_architectures/form/button: `button`: display action buttons ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: 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`. .. code-block:: 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. .. example:: .. code-block:: xml