Views#
The views are used to display records of an ModelView to the user.
In Tryton, ModelView can have several views.
An action opens a window and defines which view to show.
The views are built from XML that is stored in the view directory of
the module or in the databases thanks to the View.
So generally, they are defined in XML files with this kind of XML where name is
the name of the XML file in the view directory:
<record model="ir.ui.view" id="view_id">
<field name="model">model name</field>
<field name="type">type name</field>
<!--field name="inherit" ref="inherit_view_id"/-->
<!--field name="field_childs">field name</field-->
<field name="name">view_name</field>
</record>
There are different types of views:
Some attributes are shared by many form elements:
idA unique identifier for the tag if there is no name attribute.
yexpandA boolean to specify if the label should expand to take up any extra vertical space.
yfillA boolean to specify if the label should fill the vertical space allocated to it in the table cell.
yalignThe vertical alignment, from 0.0 to 1.0.
xexpandThe same as
yexpandbut for horizontal space.
xfillThe same as
yfillbut for horizontal space.
xalignThe horizontal alignment, from
0.0to1.0.
colspanThe number of columns the widget must take in the table.
colThe number of columns the container must have. A negative value (or zero) remove the constraint on the number of columns. The default value is
4.
statesA string of PYSON statement that is evaluated with the values of the current record.
It must return a dictionary where keys can be:
invisibleIf true, the widget is hidden.
requiredIf true, the field is required.
readonlyIf true, the field is readonly.
iconOnly for button, it must return the icon name to use or False.
pre_validateOnly for button, it contains a domain to apply on the record before calling the button.
dependsOnly for button, it must return the list of field on which the button depends.
helpThe string that is displayed when the cursor hovers over the widget.
pre_validateA boolean only for fields
trytond.model.fields.One2Manyto specify if the client must pre-validate the records usingtrytond.model.Model.pre_validate().
completionA boolean only for fields
trytond.model.fields.Many2One,trytond.model.fields.Many2Manyandtrytond.model.fields.One2Manyto specify if the client must auto-complete the field. The default value isTrue.
createA boolean to specify if the user can create targets from the widget. The default value is
True.deleteA boolean to specify if the user can delete targets from the widget. The default value is
True.
factorA factor to apply on fields
trytond.model.fields.Integer,trytond.model.fields.Floatandtrytond.model.fields.Numericto display on the widget. The default value is1.
symbolOnly on numerical fields, the name of field which provides the symbol to display.
groupingA boolean only on numerical fields to specify if the client must use grouping separators to display on the widget. The default value is
True.
help_fieldThe name of Dict field mapping the Selection value with its help string.
Form#
A form view is used to display one record.
Elements of the view are put on the screen following the rules:
Elements are placed on the screen from left to right, from top to bottom, according to the order of the XML.
The screen composed of a table with a fixed number of columns and enough rows to handle all elements.
Elements take one or more columns when they are put in the table. If there are not enough free columns on the current row, the elements are put at the beginning of the next row.
Example:
<form col="6">
<label name="name"/>
<field name="name" xexpand="1"/>
<label name="code"/>
<field name="code"/>
<label name="active"/>
<field name="active" xexpand="0" width="100"/>
<notebook colspan="6">
<page string="General">
<field name="addresses" mode="form,tree" colspan="4"
view_ids="party.address_view_form,party.address_view_tree_sequence"/>
<label name="type"/>
<field name="type" widget="selection"/>
<label name="lang"/>
<field name="lang" widget="selection"/>
<label name="website"/>
<field name="website" widget="url"/>
<separator string="Categories" colspan="4"/>
<field name="categories" colspan="4"/>
</page>
<page string="Accounting">
<label name="vat_country"/>
<field name="vat_country"/>
<label name="vat_number"/>
<field name="vat_number"/>
</page>
</notebook>
</form>
The RNG describing the XML of a form view is stored in
trytond/ir/ui/form.rng.
There is also a RNC in trytond/ir/ui/form.rnc.
form#
Each form view must start with this tag with those attributes:
on_writeThe name of a method on the Model of the view that is called when a record is saved. The method must return a list of record ids that the client must reload if they are already loaded. The function must have this syntax:
on_write(self, ids)Note
The method must be registered in
trytond.model.Model.__rpc__.creatableA boolean to specify if the form can be used to create new record. The default value is
True.cursorThe name of the field that must have the cursor by default.
scan_codeActive the scan of code using
trytond.model.ModelView.on_scan_code(). If the value isone, only one code is requested. If the value issubmit, the form is submitted after one code. If the value isloop, codes are requested until the user stops. The default value is empty.
col.
label#
Display static string with those attributes:
stringThe string that is displayed in the label.
nameThe name of the field whose description is used for string. Except if
stringis set, it uses this value and the value of the field ifstringis empty.
id, yexpand, yfill, yalign, xexpand, xfill, xalign, colspan, states, help.
It requires that either id or name is defined.
field#
Display a field of the object with the value of the current record with those attributes:
nameThe name of the field.
stringThe string that is displayed for the widget.
widgetThe widget that must be used instead of the default one.
helpThe string that is displayed when the cursor stays over the widget.
widthThe minimum width the widget should request, or -1 to unset.
heightThe minimum height the widget should request, or -1 to unset.
readonlyBoolean to set the field readonly.
modeIt is a comma separated list, that specifies the order of the view used to display the relation. (Example:
tree,form) Only forOne2Manyfields.view_idsA comma separated list that specifies the view ids used to display the relation. For
Many2OneandMany2Many, the order should always betreethenform.productOnly for
One2Manyfields, a comma separated list of target field name used to create records from the Cartesian product.completionOnly for
Many2Onefields, it is a boolean to set the completion of the field.invisibleThe field is not displayed, but it fills cells in the table.
filename_visibleOnly for
Binaryfields, boolean that enables the display of the filename.toolbarOnly for Rich Text widget, boolean that enables the display of the Rich Text toolbar. The default value is
True.spellOnly for Text widgets, a PYSON statement that is evaluated to the language code for which spell checking must be done.
borderThe type of border for the image widget. Available values are
square,roundedorcircle. The default value issquare.visibleWhen set to
1forOne2ManyandMany2Manythe client may try to read the fields of the related model using dotted notation. This result in less round trip between the client and the server at the expense of a bigger payload and a bigger query execution time.
yexpand, yfill, xexpand, xfill, colspan, help, pre_validate, completion, factor, symbol, help_field.
image#
Display an image with those attributes:
typeThe type of image source. Available values are
icon,urlorcolor. The default value isicon.nameThe image name or the field name which contains the image name. For the
icontype it must be the name of an Icon record. For theurltype it must be the URL. It can be relative to the server. For thecolortype it must be the color in#rrggbbhexadecimal.url_sizeThe name of the size parameter to add to the URL.
sizeThe size of the image in pixels. The default value is
48.borderThe type of border for the image. Available values are
square,roundedorcircle. The default value issquare.
separator#
Display a horizontal separator with those attributes:
stringThe string that is displayed above the separator.
nameThe name of the field from which the description is used for string.
id, yexpand, yfill, colspan, states, help.
It requires that either id or name is defined.
newline#
Force to use a new row.
link#
Display an Window Action as a button with a counter or one counter per tab. When clicked it opens the window. The available attributes are:
nameThe XML id of Window Action.
iconThe name of the icon to display.
emptyIf set to
hidethe button is not displayed if the counter is zero. The default isshow.
notebook#
Display a notebook which can contain page tags with the attributes:
page#
Define a tab inside a notebook with the attributes:
stringThe string that is displayed in the tab.
angleThe angle in degrees between the baseline of the label and the horizontal, measured counterclockwise.
It requires that either id or name is defined.
group#
Group widgets inside a sub-form with the attributes:
stringIf set a frame is drawn around the field with a label containing the string. Otherwise, the frame is invisible.
rowspanThe number of rows the group spans in the table.
expandableIf this attribute is present the content of the group is expandable by the user to reveal its content. A value of
1means that the group starts expanded, a value of0means that the group starts unexpanded. There is no default value.homogeneousIf
Trueall the tables cells are the same size.
col, id, yexpand, yfill, yalign, xexpand, xfill, xalign, colspan, states.
It requires that either id or name is defined.
hpaned, vpaned#
positionThe pixel position of divider, a negative value means that the position is unset.
child#
Define the two children of a hpaned or vpaned.
Tree#
A tree view is used to display records inside a list or a tree.
It is a tree if there is a field_childs defined and this tree has the drag
and drop activated if the field_childs and the parent field are defined
in the View record.
The columns of the view are put on the screen from left to right.
Example:
<tree sequence="sequence">
<field name="name"/>
<field name="percentage">
<suffix name="percentage" string="%"/>
</field>
<field name="group"/>
<field name="type"/>
<field name="active"/>
<field name="sequence" tree_invisible="1"/>
</tree>
The RNG that describes the XML for a tree view is stored in
trytond/ir/ui/tree.rng.
There is also a RNC in trytond/ir/ui/tree.rnc.
tree#
Each tree view must start with this tag with those attributes:
editableA boolean to specify if the list is editable.
creatableA boolean to specify if the editable list can be used to create new record. The default value is
true.sequenceThe name of the field that is used for sorting. This field must be an integer and it is updated to match the new sort order when the user uses “Drag and Drop” on list rows.
keyword_openA boolean to specify if the client should look for a tree_open action on double click instead of switching view.
tree_stateA boolean to specify if the client should save the state of the tree.
visualA PYSON statement that is evaluated as string
muted,success,warningordangerwith the context of the record to provide a visual context to the row.
field#
nameThe name of the field.
readonlyA boolean to set the field readonly.
widgetThe widget that must be used instead of the default one.
tree_invisibleA string of PYSON statement that is evaluated as boolean with the context of the view to display or not the column.
optionalA boolean to define if the column is hidden or not. Defining the optional attribute allows each user to show/hide the column. The attribute value is used as default when the user has no custom setting for it.
visualA PYSON statement that is evaluated as string
muted,success,warningordangerwith the context of the record to provide a visual context to the field.iconThe name of the field that contains the name of the icon to display in the column.
sumA boolean to display the sum of all the records.
widthThe width of the column.
expandAn integer that specifies if the column should be expanded to take available extra space in the view. This space is shared proportionally among all columns that have their
expandattribute set. Resize doesn’t work if this option is enabled.
prefix, suffix#
A field could contain one or many prefix or suffix that is
displayed in the same column with the attributes:
stringThe text that is displayed.
nameThe name of the field whose value is displayed.
iconThe image name or the field name which contains the image name. For the
icontype it must be the name of an Icon record. For theurltype it must be the URL and it can be relative to the server. For thecolortype it must be the color in#rrggbbhexadecimal.icon_typeThe type of icon source. Available values are
icon,urlorcolor. The default value isicon.url_sizeThe name of the size parameter to add to the URL.
borderThe type of border for the icon. Available values are
square,roundedorcircle. The default value issquare.
button#
Same as form-button with the addition of:
widthThe width of the column.
multipleA boolean to execute the button on the selected record.
List-Form#
A List-forms view displays records as a list of editable forms. It uses the same schema as the form views.
Note
The performance of the list-form does not allow to scale well for large number of records
Graph#
A graph view is used to display records in graph.
Example:
<graph string="Invoice by date" type="vbar">
<x>
<field name="invoice_date"/>
</x>
<y>
<field name="total_amount"/>
</y>
</graph>
The RNG that describes the XML for a graph view is stored in
trytond/ir/ui/graph.rng.
There is also a RNC in trytond/ir/ui/graph.rnc.
graph#
Each graph view must start with this tag with those attributes:
typeThe type of graph:
vbar,hbar,line,pie.backgroundAn hexadecimal value for the color of the background.
colorThe main color.
legendA boolean to specify if the legend must be displayed.
x, y#
Describe the field that must be used for axis.
x must contain only one tag field and y must at least one but may
contain many.
field#
nameThe name of the field on the record to use.
stringThe string to use as label for the field.
keyUsed to distinguish fields with the same name but with different domain.
domainA PySON statement which is evaluated with the record value as context. If the result is true the field value is added to the graph.
fillDefine if the graph is filled.
emptyDefine if the line graph must put a point for missing dates.
colorThe color of the field.
interpolationDefine how the line graph must interpolate points. The default is
linear.constant-centerUse the value of the nearest point, see Nearest-neighbor interpolation
constant-leftUse the value of the nearest left point.
constant-rightUse the value of the nearest right point.
linear
Board#
Board view is used to display multiple views at once.
Elements are put on the screen following the same rules as for Form view.
The views can be updated by the selection of records on an other view inside
the same board by using in the domain the active_id or active_ids from
the _actions dictionary with the action id of the other view as key.
For example:
<field
name="domain"
pyson="1"
eval="[('field', '=', Eval('_actions', {}).get('module.action_id', {}).get('active_id'))]"/>
The RNG that describes the XML for a board view is stored in
trytond/ir/ui/board.rng.
There is also a RNC in trytond/ir/ui/graph.rnc.
board#
Each board view must start with this tag with the attribute:
col.
image#
Same as form-image.
separator#
Same as form-separator.
label#
Same as form-label.
newline#
Same as form-newline.
notebook#
Same as form-notebook.
page#
Same as form-page.
group#
Same as form-group.
hpaned, vpaned#
Same as form-paned.
child#
Same as form-child.
action#
nameThe id of the action window.
Calendar#
Calendar view is use to display records as events on a calendar based on a
dtstart and optionally a dtend.
Example:
<calendar dtstart="planned_date">
<field name="code"/>
<field name="product"/>
<field name="reference"/>
</calendar>
The RNG that describes the XML for a calendar view is stored in
trytond/ir/ui/calendar.rng.
There is also a RNC in trytond/ir/ui/calendar.rnc.
The calendar_scroll_time context key determines the initial time to scroll
to.
The default value is datetime.time(6).
calendar#
Each calendar view must start with this tag with those attributes:
dtstartThe name of the field that contains the start date.
dtendThe name of the field that contains the end date.
modeAn optional name for the mode that is used first. Available views are:
day,weekandmonth. The default value ismonth.editableA boolean to specify if the calendar is editable. The default value is
True.colorAn optional field name that contains the text color for the event. The default value is
black.background_colorAn optional field name that contains the background color for the event. The default value is
lightblue.widthThe minimum width the calendar should request, use -1 to unset.
heightThe minimum height the calendar should request, use -1 to unset.
field#
nameThe name of the field.