.. _reference/views:
=====
Views
=====
Views are what define how records should be displayed to end-users. They are specified in XML which
means that they can be edited independently from the models that they represent. They are flexible
and allow a high level of customization of the screens that they control. There exist various types
of views. Each of them represents a mode of visualization: *form*, *list*, *kanban*, etc.
.. todo:: Build doc of ir_ui_view.py ?
.. _reference/views/structure:
Generic structure
=================
Basic views generally share the common structure defined below. Placeholders are denoted in all
caps.
.. code-block:: xml
NAMEMODEL
Fields
======
View objects expose a number of fields. They are optional unless specified otherwise.
* ``name`` (mandatory) :class:`~odoo.fields.Char`
Only useful as a mnemonic/description of the view when looking for one in a list of some sort.
* ``model`` :class:`~odoo.fields.Char`
The model linked to the view, if applicable.
* ``priority`` :class:`~odoo.fields.Integer`
When a view is requested by ``(model, type)``, the view matching the model and
the type, with the lowest priority will be returned (it is the default view).
It also defines the order of views application during :ref:`view
inheritance `.
* ``groups_id`` :class:`~odoo.fields.Many2many` -> :class:`odoo.addons.base.models.res_users.Groups`
The groups allowed to use/access the current view.
If the view extends an existing view, the extension will only be applied
for a given user if the user has access to the provided ``groups_id``.
* ``arch`` :class:`~odoo.fields.Text`
The description of the view layout.
Attributes
==========
.. todo::
view attributes & view element attributes
attrs & states attributes are missing generic information
The different view types have a wide variety of attributes allowing customizations of
the generic behaviors. Some main attributes will be explained here. They do not all have
an impact on all view types.
.. note:: The current context and user access rights may also impact the view abilities.
.. todo:: info on create/... in the context ?
* ``create``
Disable/enable record creation on the view.
* ``edit`` (``form`` & ``list`` & ``gantt``)
Disable/enable record editing on the view.
* ``delete`` (``form`` & ``list``)
Disable/enable record deletion on the view through the **Action** dropdown.
* ``duplicate`` (``form``)
Disable/enable record duplication on the view through the **Action** dropdown.
* ``decoration-{$name}`` (``list`` & ``gantt``)
Define a conditional display of a record in the style of a row's text based on the corresponding
record's attributes.
Values are Python expressions. For each record, the expression is evaluated
with the record's attributes as context values and if ``true``, the
corresponding style is applied to the row. Here are some of the other values
available in the context:
* ``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``.
.. code-block:: xml
.. warning::
Supported values differ for the two view types. The Gantt view only supports ``success``,
``info``, ``warning``, ``danger`` and ``secondary`` displays. The list view supports ``bf``,
``it``, ``success``, ``info``, ``warning``, ``danger``, ``muted`` and ``primary`` displays.
* ``sample`` (``kanban`` & ``list`` & ``gantt`` & ``graph`` & ``pivot`` & ``cohort``)
Populate the view with a set of sample records if none are found for the current model.
This attribute is false by default.
These fake records will 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 will not be able to interact with these data and they will be discarded as soon as
an action is performed (record created, column added, etc.)
* ``banner_route``
a route address to be fetched and prepended to the view.
If this attribute is set, the
:ref:`controller route url` will be fetched and
displayed above the view. The json response from the controller should
contain an "html" key.
If the html contains a stylesheet tag, it will be
removed and appended to .
To interact with the backend you can use tags. Please take
a look at the documentation of the _onActionClicked method of
AbstractController (*addons/web/static/src/js/views/abstract_controller.js*)
for more details.
Only views extending AbstractView and AbstractController can use this
attribute, like :ref:`reference/views/form`, :ref:`reference/views/kanban`,
:ref:`reference/views/list`, ...
Example:
.. code-block:: xml
.. code-block:: python
class MyController(odoo.http.Controller):
@http.route('/module_name/hello', auth='user', type='json')
def hello(self):
return {
'html': """