================= View architecture ================= Generic view ============ The architecture of a view is defined by XML data interpreted by the JavaScript framework. For each view, there is a :file:`\*.rng` file defining the attributes and possible architectures. .. note:: The current context and user access rights may also impact the view abilities. .. seealso:: :doc:`view_records` .. _reference/view_architecture/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; - `parent`: the record that refers to the container; only inside sub-views of :ref:`relational fields `; - `context` (dict_): the current view's context; - `uid` (integer_): the id of the current user; - `today` (string_): the current local date in the `YYYY-MM-DD` format; - `now` (string_): the current local datetime in the `YYYY-MM-DD hh:mm:ss` format. .. example:: .. code-block:: xml .. example:: .. code-block:: xml
.. .................................................................... .. _reference/view_architecture/form: Form ==== Form views are used to display the data from a single record. Their root element is ``
``. They are composed of regular HTML_ with additional structural and semantic components. .. code-block:: xml ...
Optional attributes_ are added on root element ``
`` to customize the view. :string: 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) :create: boolean_ (default: ``True``) Disable/enable record creation on the view. :edit: boolean_ (default: ``True``) Disable/enable record editing on the view. :duplicate: boolean_ (default: ``True``) Disable/enable record duplication on the view through the **Action** dropdown. :delete: boolean_ (default: ``True``) Disable/enable record deletion on the view through the **Action** dropdown. :js_class: string_ (optional) Name of the javascript component the webclient will instantiating instead of the form the view. :disable_autofocus: boolean_ (default: ``False``) Disable automatic focussing of the first field in the view. .. _reference/view_architecture/form/semantic: Semantic components ------------------- Semantic components tie into the Odoo system and allow interaction with it. remark: (with the remark style) Placeholders are denoted in all caps. .. _reference/view_architecture/form/field: : render formatted values ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: xml renders (and allow editing of, possibly) a single field of the current record. Using several times a field in a form view is supported and the fields can receive different values for modifiers 'invisible' and 'readonly'. This fields have the same values but can be display differentaly. However, the behavior is not guaranteed when several fields exist with different values for modifier 'required'. ```` can have the following attributes: :name: string_ (mandatory) :ref:`model ` field name the name of the field to render :string: string_ (default: `string` value from :class:`~odoo.fields.Field`) the label to display. By default display the field's label coming from the field definition in the model. :id: string_ (optional) the node id. Useful when there are several occurrences of the same field in the view (see ``label`` component below). Default is the field name. :widget: string_ (optional) fields have a default rendering based on their type (e.g. :class:`~odoo.fields.Char`, :class:`~odoo.fields.Many2one`). The ``widget`` attributes allows using a different rendering method and context. See more information in :ref:`reference/js/widgets` .. code-block:: xml :options: :ref:`python expression ` that evaluates to a dict_ (default: ``{}``) JSON object specifying configuration option for the field's widget (including default widgets) .. code-block:: xml :groups: `Comma-separated values`_ (optional) whose choices are the :class:`~odoo.addons.base.models.res_users.Groups` reference only displays the field for specific users .. code-block:: xml :domain: :ref:`python expression ` that evaluates to a :ref:`reference/orm/domains` (default: ``[]``) for relational fields only, filters to apply when displaying existing records for selection .. code-block:: xml :context: :ref:`python expression ` that evaluates to a dict_ (default: ``{}``) for relational fields only, context to pass when fetching possible values. The default values ``default_FIELD_NAME`` (e.g. ``{'default_name': 'toto'}``) will be used to create the linked record. ``OTHER_BUSINESS_KEY`` is every keys depending of the model/module. .. code-block:: xml :readonly: :ref:`python expression ` that evaluates to a boolean_ (default: ``False``) Whether the field can be modified by the user (``False``) or is read only (``True``). .. code-block:: xml :required: :ref:`python expression ` that evaluates to a boolean_ (default: ``False``) Whether the field can be left empty (``False``) or must be set (``True``). .. code-block:: xml :invisible: :ref:`python expression ` that evaluates to a boolean_ (default: ``False``) Whether the field can be visible (``False``) or must be hide (``True``). There are two uses for field ``invisible`` attribute: * Usability: not to overload the view and to make it easier for the user to read depending on the content; * Technical: fetched by the webclient for evaluating :ref:`python expression ` .. code-block:: xml :nolabel: boolean_ (default: ``False``) if ``True``, do not automatically display the field's label, only makes sense if the field is a direct child of a ``group`` element :placeholder: string_ (optional) help message to display in *empty* fields. Can replace field labels in complex forms. *Should not* be an example of data as users are liable to confuse placeholder text with filled fields :mode: `Comma-separated values`_ (default: ``tree``) whose choices are: ``kanban``, ``from``, ``tree`` for :class:`~odoo.fields.One2many`, display mode (view type) to use for the field's linked records. One of ``tree``, ``form``, ``kanban`` or ``graph``. The default is ``tree`` (a list display) :help: string_ (optional) tooltip displayed for users when hovering the field or its label :class: string_ (optional) `HTML class`_ `HTML class`_ to set on the generated element. The styling use the Bootstrap_ framework and :doc:`UI icons `. Below are the common Odoo_ classes: ``oe_inline``: prevent the usual line break following fields and limit their span. ``oe_left``, ``oe_right``: floats_ the field to the corresponding direction ``oe_read_only``, ``oe_edit_only``: only displays the field in the corresponding form mode ``oe_avatar``: for image fields, displays images as "avatar" (square, 90x90 maximum size, some image decorations) :filename: string_ (optional) for binary fields, name of the related field providing the name of the file :password: boolean_ (default: ``False``) if is ``True`` indicates that a :class:`~odoo.fields.Char` field stores a password and that its data shouldn't be displayed :kanban_view_ref: string_ (optional) defined by the pattern: ``%(ADDON.MODEL_view_TYPE)s`` (target the :doc:`view reference `) for opening specific kanban view when selecting records from m2o/m2m in mobile environment :default_focus: boolean_ (default: ``False``) If True, defines that this field is the fields that will be focussed when the view opens. Cannot be present on more than one field of a view. .. note:: :ref:`Relational fields ` node can contain specific subviews. .. code-block:: xml
.. _reference/view_architecture/form/label: