Skip to main content
Version: Tryton 7.0 (LTS)

2. Anatomy of a module

Tryton 7.0 · versioned practical course

Objectives

  • recognize every module component
  • register a first model in the Pool
  • activate and upgrade the module safely

Mental model

A module is a Python package plus Tryton metadata. Python defines behavior; XML and CSV connect records, views, actions, translations, and access rights.

Guided practice

  1. Create the package and tryton.cfg.
  2. Define a ModelSQL and ModelView class.
  3. Register it from init.py.
  4. Load XML and access CSV in dependency order.
  5. Update the module list, activate the module, then test an upgrade.

Minimal example

[tryton]
version=7.0.0
depends:
ir
res
xml:
library.xml

# library.py
from trytond.model import ModelSQL, ModelView, fields

class Book(ModelSQL, ModelView):
"Library Book"
__name__ = 'library.book'
title = fields.Char("Title", required=True)

# __init__.py
from trytond.pool import Pool
from . import library

def register():
Pool.register(library.Book, module='library', type_='model')

How to read the example

The technical model name is stable database/API identity. The class name is Python identity. Registration tells the Pool which classes compose the final model.

Exercise

Add an ISBN field, upgrade the database, and inspect the model from a test instead of editing SQL manually.

Run the exercise first with a minimal valid case, then add an invalid case and turn both into repeatable tests.

Verifiable result

The module activates, creates its table, and upgrades without losing the first book.

Common mistakes

  • forgetting relative imports
  • loading XML before referenced records
  • renaming XML IDs after release
  • declaring dependencies that are not actually needed

Ready-to-advance criteria

  • I can explain the concepts without looking at the code.
  • Valid and invalid cases have tests.
  • I tested with a non-administrative user.
  • I know how to upgrade and restore the training database.

Version and references

Series 7.0 requires at least Python 3.8 according to official metadata. This official branch still carries historical metadata in setup.py; preserve series compatibility while preparing custom packages for standard python -m build builds. Do not confuse this historical minimum with the Python version certified by your organization.

This edition pins examples and dependencies to series 7.0. Check the official 7.0 tutorial, server API, and source branch before moving a pattern to production.