Modules#
The modules of Tryton extend the functionality of the platform.
The server comes by default with only a 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.
It must contains a method named register() that must register to the pool
all the objects of the module.
tryton.cfg file#
It is a configuration file using the format of ConfigParser that must
contain tryton section with this following keys:
versionThe version number of the module.
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.
Here is an example:
[tryton]
version=0.0.1
depends:
ir
res
country
xml:
party.xml
category.xml
address.xml
contact_mechanism.xml
Python Files#
The Python files define the models for the modules.
XML Files#
The XML files define data that are inserted into the database on activation.
There is an RNC for those files stored in trytond/tryton.rnc.
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 the tags:
trytonThe main 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 attributes:searchOnly for relation field. It contains a domain which is used to search for the value to use. The first value found will be used.
refOnly for relation field. 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 considered 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.