Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
168 lines (113 sloc) 4.29 KB

Basic Concepts


:py:class:`~trytond.model.Model([id[,**kwargs]])` This is the base class that every kind of model inherits.

The most commonly used type of models are:

For API-Reference about Models in tryton refer to Trytond docs: :py:mod:`~trytond.model`

Most likely your custom Model will inherit from ModelSql and ModelView at least, so it can be stored and viewed in the client.

Each :py:class:`~trytond.model.ModelSQL` can hold a set of tryton-fields to represent its attributes. For a complete list of field types available on tryton you are refered to Trytond docs: :py:mod:`~trytond.model.fields`


Tryton provides a Pool to serve all your Models in a thread-safe way. The Pool can contain the following types:

  • model
  • wizard
  • report

You can therefore obtain a model-class from anywhere in your module with the help of a Pool() instance:

Books = Pool().get('')  # Model
book_no_one = Books(1)  # Instance

Model Inheritance

To extend an existing model (like Company), one only needs to instantiate a class with the same __name__ attribute:

from trytond.model import fields
from trytond.pool import PoolMeta

__metaclass__ = PoolMeta

class Company:
    __name__ = ''
    company_code = fields.Char('Company Code')

and register the model to the pool (using a different module name)

    module='company_customized', type='model')


Most of trytons behaviour is itself defined by records of internal models (ir). All records are stored in the database and they can created within the client or statically predefined in xml files. When you are unsure about how to define the records, you are encouraged to explore the models in:



The views are used to display records of an object to the user. In tryton, models can have several views, it is the action, that opens the window, that tells which views must be used. The view are built using XML that is stored in the module's view diectory or can be stored in database with the So generally, they are defined in xml files with this kind of xml:

Extending Views

Each inherit view must start with data tag. xpath tag is used which specifies the location where the field is to be added.

  • expr: the xpath expression to find a node in the inherited view.
    • selecting elements starting from "/"
    • selecting one of a set of elements by querying attributes: [@attribute='value']
  • position: Define the position of xml-injection.
    • before
    • after
    • replace
    • inside
    • replace_attributes (which will change the attributes)



A wizard is a finite state machine.

:py:class:`~trytond.wizard.Wizard(session_id)` This is the base for any wizard. It contains the engine for the finite state machine. A wizard must have some state instance attributes that the engine will use.

Class attributes are: Wizard.__name__ It contains the unique name to reference the wizard throughout the platform.

Active Records