Thursday 10 December 2015

XML view Description



Common Structure

View objects expose a number of fields, they are optional unless specified otherwise.
name (mandatory)
only useful as a mnemonic/description of the view when looking for one in a list of some sort
model
the model linked to the view, if applicable (it doesn't for QWeb views)
priority
client programs can request views by id, or by (model, type). For the latter, all the views for the right type and model will be searched, and the one with the lowest priority number will be returned (it is the "default view").
priority also defines the order of application during view inheritance.
arch
the description of the view's layout
groups_id
Many2many field to the groups allowed to view/use the current view
inherit_id
the current view's parent view, see Inheritance, unset by default
mode
inheritance mode, see Inheritance. If inherit_id is unset the mode can only be primary. If inherit_id is set,extension by default but can be explicitly set to primary
application
website feature defining togglable views. By default, views are always applied

Inheritance

View matching

  • if a view is requested by (model, type), the view with the right model and type, mode=primary and the lowest priority is matched
  • when a view is requested by id, if its mode is not primary its closest parent with mode primary is matched

View resolution

Resolution generates the final arch for a requested/matched primary view:
  1. if the view has a parent, the parent is fully resolved then the current view's inheritance specs are applied
  2. if the view has no parent, its arch is used as-is
  3. the current view's children with mode extension are looked up and their inheritance specs are applied depth-first (a child view is applied, then its children, then its siblings)
The result of applying children views yields the final arch

Inheritance specs

There are three types of inheritance specs:
  • An xpath element with an expr attribute. expr is an XPath expression2 applied to the current arch, the first node it finds is the match
  • field element with a name attribute, matches the first field with the same name
  • any other element, the first element with the same name and identical attributes (ignoring position) is matched
The inheritance spec may have an optional position attribute specifying how the matched node should be altered:
inside (default)
the content of the inheritance spec is appended to the matched node
replace
the content of the inheritance spec replaces the matched node
after
the content of the inheritance spec is added to the matched node's parent, after the matched node
before
the content of the inheritance spec is added to the matched node's parent, before the matched node
attributes
the content of the inheritance spec should be attribute elements with a name attribute and an optional body:
  • if the attribute element has a body, a new attributed named after its name is created on the matched node with theattribute element's text as value
  • if the attribute element has no body, the attribute named after its name is removed from the matched node. If no such attribute exists, an error is raised
A view's specs are applied sequentially.

Lists

The root element of list views is <tree>3. The list view's root can have the following attributes:
editable
by default, selecting a list view's row opens the corresponding form view The editable attributes makes the list view itself editable in-place.
Valid values are top and bottom, making new records appear respectively at the top or 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
default_order
overrides the ordering of the view, replacing the model's default order. The value is a comma-separated list of fields, postfixed by desc to sort in reverse order:
<tree default_order="sequence,name desc">
colors


allows changing the color of a row's text based on the corresponding record's attributes.
Defined as a mapping of colors to Python expressions. Values are of the form: color:expr[;...]. For each record, pairs are tested in order, the expression is evaluated for the record and if true the corresponding color is applied to the row. If no color matches, uses the default text color (black).
  • color can be any valid CSS color unit.
  • expr should be a Python expression evaluated with the current record's attributes as context values. Other context values are uid (the id of the current user) and current_date (the current date as a string of the form yyyy-MM-dd)
fonts
allows changing a row's font style based on the corresponding record's attributes.
The format is the same as for color, but the color of each pair is replaced by bolditalic or underline, the expression evaluating to true will apply the corresponding style to the row's text. Contrary to colors, multiple pairs can match each record
createeditdelete
allows disabling the corresponding action in the view by setting the corresponding attribute to false
on_write
only makes sense on an editable list. Should be the name of a method on the list's model. The method will be called with the id of a record after having created or edited that record (in database).
The method should return a list of ids of other records to load or update.

Possible children elements of the list view are:
button
displays a button in a list cell
icon
icon to use to display the button
string
  • if there is no icon, the button's text
  • if there is an iconalt text for the icon
type
type of button, indicates how it clicking it affects Odoo:
workflow (default)
sends a signal to a workflow. The button's name is the workflow signal, the row's record is passed as argument to the signal
object
call a method on the list's model. The button's name is the method, which is called with the current row's record id and the current context.
action
load an execute an ir.actions, the button's name is the database id of the action. The context is expanded with the list's model (as active_model), the current row's record (active_id) and all the records currently loaded in the list (active_ids, may be just a subset of the database records matching the current search)
name
see type
args
see type
attrs
dynamic attributes based on record values.
A mapping of attributes to domains, domains are evaluated in the context of the current row's record, if True the corresponding attribute is set on the cell.
Possible attributes are invisible (hides the button) and readonly (disables the button but still shows it)
states
shorthand for invisible attrs: a list of states, comma separated, requires that the model has a state field and that it is used in the view.
Makes the button invisible if the record is not in one of the listed states
context
merged into the view's context when performing the button's Odoo call
confirm
confirmation message to display (and for the user to accept) before performing the button's Odoo call
field
defines a column where the corresponding field should be displayed for each record. Can use the following attributes:
name
the name of the field to display in the current model. A given name can only be used once per view
string
the title of the field's column (by default, uses the string of the model's field)
invisible
fetches and stores the field, but doesn't display the column in the table. Necessary for fields which shouldn't be displayed but are used by e.g. @colors
groups
lists the groups which should be able to see the field
widget
alternate representations for a field's display. Possible list view values are:
progressbar
displays float fields as a progress bar.
many2onebutton
replaces the m2o field's value by a checkmark if the field is filled, and a cross if it is not
handle
for sequence fields, instead of displaying the field's value just displays a dra&drop icon
sumavg
displays the corresponding aggregate at the bottom of the column. The aggregation is only computed on currently displayed records. The aggregation operation must match the corresponding field's group_operator
attrs
dynamic attributes based on record values. Only effects the current field, so e.g. invisible will hide the field but leave the same field of other records visible, it will not hide the column itself.

No comments:

Post a Comment