Je vais réaliser un 1er module Tryton (simpliste) en partant de l'exemple réalisé sous OpenERP.
Je me limiterai pour ce 1er module à l'écran "Author".
Il n'y aura pas de gestion des droits d'accès, ni de traduction.
Environnement
- serveur Tryton 3.0 sur un serveur virtualisé Debian 7.3 (wheezy)
- client Tryton 3.0 sur PC Linux Mint 14
- Installation Tryton faite selon la procédure précédente
- serveur Tryton lancé
- Le résultat à obtenir est :
* Vue "Tree"
* Vue "Form"
- Nous allons créer les répertoires et fichiers suivants :
- Après avoir créé :
* le répertoire mylibrary sous /usr/lib/python2.7/dist-packages/trytond/modules
* le sous-répertoire view sous mylibrary
- Nous allons créer les fichiers suivants :
* __init__.py :
from trytond.pool import Pool
from .mylibrary import *
def register():
Pool.register(
Author,
module='mylibrary', type_='model'
)
* tryton.cfg :
[tryton]
version=3.0.0
xml:
mylibrary.xml
* mylibrary.py :
from trytond.model import ModelView, ModelSQL, fields
__all__ = ['Author']
class Author(ModelSQL, ModelView):
'Author'
__name__ = 'mylibrary.author'
firstname = fields.Char('FirstName', required=True)
lastname = fields.Char('LastName', required=True)
* mylibrary.xml :
<?xml version="1.0"?>
<tryton>
<data>
<record model="ir.ui.view" id="author_view_form">
<field name="model">mylibrary.author</field>
<field name="type">form</field>
<field name="name">author_form</field>
</record>
<record model="ir.ui.view" id="author_view_tree">
<field name="model">mylibrary.author</field>
<field name="type">tree</field>
<field name="name">author_tree</field>
</record>
<record model="ir.action.act_window" id="act_author_form">
<field name="name">Author</field>
<field name="res_model">mylibrary.author</field>
</record>
<record model="ir.action.act_window.view" id="act_author_form_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="author_view_tree"/>
<field name="act_window" ref="act_author_form"/>
</record>
<record model="ir.action.act_window.view" id="act_author_form_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="author_view_form"/>
<field name="act_window" ref="act_author_form"/>
</record>
<menuitem name="MyLibrary" sequence="0" id="menu_mylibrary"/>
<menuitem name="Author" parent="menu_mylibrary" id="menu_author" action="act_author_form"/>
</data>
</tryton>
* view/author_form.xml :
<?xml version="1.0"?>
<form string="Author" >
<label name="firstname"/>
<field name="firstname"/>
<label name="lastname"/>
<field name="lastname"/>
</form>
* view/author_tree.xml :
<?xml version="1.0"?>
<tree string="Addresses">
<field name="firstname"/>
<field name="lastname"/>
</tree>
- installer le module mylibrary
/usr/bin/trytond -i mylibrary -d <nom BD>
- relancer le serveur Tryton
/etc/init.d/tryton-server restart
- recharger le menu du client Tryton
... le module est alors opérationnel !!
Pour plus d'info, se reporter au wiki.
Modification du module:
Pour faire prendre en compte une modification du module, il faut faire :
/usr/bin/trytond -u mylibrary -d <nom BD>