Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module A minimal module A tryton module creation crash course Defining some object / tables Defining a tree and a form view Default values N. Évrard Some more advanced features

Workflows B2CK Buttons Function fields Wizards

Extending Tryton Unconference Leipzig 2014 pre-existing tryton objects

Extending models Extending views Outline

Tryton Crash Course 1 Installing tryton N. Évrard Prerequisites Installing tryton Initializing tryton Prerequisites Initializing tryton 2 A basic module A basic module

A minimal module A minimal module Defining some object / tables Defining some object / tables Defining a tree and a form view Defining a tree and a form view Default values Default values Some more advanced features 3 Some more advanced features Workflows Buttons Workflows Function fields Wizards Buttons

Extending Function fields pre-existing tryton objects Wizards Extending models Extending views 4 Extending pre-existing tryton objects Extending models Extending views Python good practices (pip & virtualenv)

Tryton Crash Course

N. Évrard

Installing tryton Prerequisites pip is THE tool for installing and managing Python packages. Initializing tryton virtualenv is THE tool used to create isolated Python environment. A basic module A minimal module create isolated Python environments Defining some object / tables Do not mix different version of your libraries / applications Defining a tree and a form view Installation of packages in the user $HOME Default values

Some more pip install virtualenv (or your distro package manager) advanced features Workflows virtualenv --system-site-packages .venv/trytond Buttons Function fields source .venv/trytond/bin/activate Wizards Extending hgnested is a extension. The tryton project use it to easily pre-existing tryton objects apply the same command on nested repositories. Extending models Extending views Installing trytond

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module Example A minimal module Defining some object / tables Defining a tree and a $ hg nclone http://hg.tryton.org/trytond -b 3.4 form view Default values $ cd trytond Some more $ pip install -e . advanced features Workflows $ pip install vobject Buttons Function fields Wizards

Extending pre-existing tryton objects

Extending models Extending views Setting up a trytond config file

Tryton Crash Course

N. Évrard Here is a minimal example of a configuration file. You should save it in $HOME/.trytond.conf Installing tryton

Prerequisites Initializing tryton Example A basic module

A minimal module Defining some object / tables [] Defining a tree and a form view path = /home/training/ Default values

Some more advanced features

Workflows Buttons We will set the TRYTOND_CONFIG environment variable Function fields Wizards Example Extending pre-existing tryton objects Extending models $ export TRYTOND_CONFIG=$HOME/.trytond.conf Extending views Initializing a minimal trytond database

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module Example A minimal module Defining some object / tables Defining a tree and a $ touch ~/databases/test. form view Default values $ ./bin/trytond -d test -u ir res

Some more advanced features

Workflows Buttons Function fields trytond will ask you for the admin password at the end of the installation Wizards process. Extending pre-existing tryton objects

Extending models Extending views Adding a new modules

Tryton Crash Course

N. Évrard

Installing tryton Prerequisites In this tutorial we will use a MQ repository in order to progress step by Initializing tryton step. A basic module

A minimal module Defining some object / Example tables Defining a tree and a form view Default values $ cd trytond/modules Some more advanced features $ hg init training Workflows $ cd training/.hg Buttons Function fields $ hg clone http://hg.tryton.org/training -b 3.4 patches Wizards

Extending pre-existing tryton objects

Extending models Extending views A minimal trytond modules

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module

A minimal module Defining some object / A minimal trytond modules needs two files: tables Defining a tree and a form view __init__.py the usual file needed by all python modules Default values tryton.cfg the file that helps tryton glue together model and view Some more advanced features definitions Workflows Buttons Function fields Wizards

Extending pre-existing tryton objects

Extending models Extending views The content of tryton.cfg

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton Example A basic module

A minimal module Defining some object / tables [tryton] Defining a tree and a form view version=0.0.1 Default values depends: Some more advanced features ir Workflows Buttons res Function fields Wizards

Extending pre-existing tryton objects

Extending models Extending views Creating a model

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module A minimal module Example Defining some object / tables Defining a tree and a from trytond .model import ModelSQL form view Default values __all__ = [ ’Opportunity’]

Some more class Opportunity (ModelSQL): advanced features ’Opportunity ’ Workflows __name__ = ’training.opportunity ’ Buttons Function fields Wizards

Extending pre-existing tryton objects

Extending models Extending views Register the model

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module A minimal module Example Defining some object / tables Defining a tree and a from trytond.pool import Pool form view from .opportunity import ∗ Default values def register (): Some more Pool.register( advanced features Opportunity , Workflows module=’training ’ , type_=’model’) Buttons Function fields Wizards

Extending pre-existing tryton objects

Extending models Extending views Adding fields to a model

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module Example

A minimal module Defining some object / class Opportunity (ModelSQL): tables ’Opportunity ’ Defining a tree and a __name__ = ’training.opportunity ’ form view _rec_name = ’description ’ Default values description = fields.Char( ’Description ’, required=True) Some more start_date = fields.Date( ’Start Date’, advanced features required=True) Workflows end_date = fields.Date( ’End Date’) Buttons party = fields.Many2One( ’party.party ’, ’Party ’ , required=True) Function fields comment = fields .Text( ’Comment’) Wizards

Extending pre-existing tryton objects

Extending models Extending views Displaying data

Tryton Crash Course

N. Évrard To use the presentation layer your model must inherit from ModelView Installing tryton

Prerequisites Initializing tryton Example

A basic module class Opportunity(ModelSQL, ModelView): A minimal module Defining some object / tables Defining a tree and a form view You must also add the xml presentation file in the tryton.cfg Default values configuration file Some more advanced features Workflows Example Buttons Function fields Wizards xml: Extending pre-existing tryton opportunity.xml objects

Extending models Extending views Defining a view

Tryton Crash Course

N. Évrard

Installing tryton

Prerequisites Initializing tryton

A basic module

A minimal module Defining some object / trytond/ir/ui/view.py tables View objects are normal tryton objects ( ) Defining a tree and a form view Two kind of view: Default values

Some more Tree view a list of record advanced features Form view a view for editing/creating one record Workflows Buttons Function fields Wizards

Extending pre-existing tryton objects

Extending models Extending views A tree view

Tryton Crash Course

N. Évrard

Installing tryton Prerequisites Example Initializing tryton

A basic module

A minimal module training .opportunity tree Defining some object / tables opportunity_list < / record> Defining a tree and a form view Default values

Some more advanced features Example Workflows

Buttons Function fields Wizards Extending pre-existing tryton < / t r e e > objects

Extending models Extending views A form view

Tryton Crash Course

N. Évrard Example Installing tryton

Prerequisites Initializing tryton training .opportunity form A basic module opportunity_form A minimal module < / record> Defining some object / tables Defining a tree and a form view Default values Example Some more advanced features

Workflows