Modules#
The modules of Tryton extend the functionality of the platform.
The server comes by default with only basic functionality included in these
modules: ir, res.
Module Structure#
A module is a directory in trytond/modules which contains at least two
files:
__init__.pyA Tryton module must be a Python module.
tryton.cfgA Configuration file that describes the Tryton module.
__init__.py file#
It is the Python __init__.py to define a module.
tryton.cfg file#
This is a configuration file that uses the ConfigParser format and must
contain a [tryton] section with the following keys:
versionThe version number of the module.
Note
When using the setup.py generated by the cookiecutter template, the
major and minor part of this version (X.Y.*) must match the version of the
Tryton server the module is for.
dependsA one per line list of modules on which this module depends.
extras_dependA one per line list of modules on which this module may depend.
xmlThe one per line list of the XML files of the module. They will be loaded in the given order when the module is activated or updated.
It may contain some [register] or [register <module> <module>] sections
with the keys model, wizard and report defining the type_ and
qualified name of class relative to the module as a one per line list to pass
to register().
Note
The <module> in the section name set the depends.
And it also may contain a [register_mixin] which define the pair of
qualified name relative to the module of mixin and subsclass to pass to
register_mixin().
Here is an example:
[tryton]
version=0.0.1
depends:
country
ir
res
xml:
party.xml
category.xml
address.xml
contact_mechanism.xml
[register]
model:
category.Category
party.Party
address.Address
contact_mechanism.ContactMechanism
wizard:
party.Replace
Python Files#
The Python files define the models for the modules.
XML Files#
The XML files define the data that is inserted into the database on activation.
The trytond/tryton.rng and trytond/tryton.rnc files contain a
RELAX NG XML schema for these files
in XML syntax and compact syntax respectively.
The following snippet gives a first idea of what an XML file looks:
<?xml version="1.0"?>
<tryton>
<data>
<record model="res.group" id="group_party_admin">
<field name="name">Party Administration</field>
</record>
<record model="res.user-res.group"
id="user_admin_group_party_admin">
<field name="user" ref="res.user_admin"/>
<field name="group" ref="group_party_admin"/>
</record>
<menuitem
name="Party Management"
sequence="0"
id="menu_party"
icon="tryton-users"/>
<record model="ir.ui.view" id="party_view_tree">
<field name="model">party.party</field>
<field name="type">tree</field>
<field name="arch">
<![CDATA[
<tree string="Parties">
<field name="code"/>
<field name="name"/>
<field name="lang"/>
<field name="vat_code"/>
<field name="active" tree_invisible="1"/>
<field name="vat_country" tree_invisible="1"/>
<field name="vat_number" tree_invisible="1"/>
</tree>
]]>
</field>
</record>
</data>
</tryton>
Here is the list of valid tags:
trytonThe root tag of the XML.
dataDefine a set of data inside the file. It can have the attributes:
noupdatePrevent the framework to update the records,
dependsImport data only if all modules in the comma separated module list value are activated,
groupedCreate records at the end with a grouped call.
languageImport data only if the language is translatable.
recordCreate a record of the model defined by the attribute
modelin the database. Theidattribute can be used to refer to the record later in any XML file.fieldSet the value of the field with the name defined by the attribute
name. Here is the list of valid attributes:searchOnly for relation fields. It contains a domain which is used to search for the value to use. The first value found will be used.
refOnly for relation fields. It contains an XML id of the relation to use as value. It must be prefixed by the module name with an ending dot, if the record is defined in an other module.
evalPython code to evaluate and use result as value. The following expressions are available:
pysonConvert the evaluated value into PYSON string.
dependsSet value only if all modules in the comma separated module list value are activated.
Note
Field content is treated as a string. So for fields that require other types, it is required to use the
evalattribute.menuitemShortcut to create Menu records. Here is the list of attributes:
idThe id of the menu.
nameThe name of the menu.
iconThe icon of the menu.
sequenceThe sequence value used to order the menu entries.
parentThe XML id of the parent menu.
actionThe XML id of the action linked to the menu.
groupsA list of XML id of group, that have access to the menu, separated by commas.
activeA boolean telling if the menu is active or not.