Skip to main content
Version: Tryton 8.0 (LTS)

9. Extend modules without breaking them

Tryton 8.0 · versioned practical course

Objectives

  • extend a core model with PoolMeta
  • preserve cooperative inheritance
  • modify views through stable XML references

Mental model

The Pool composes classes from installed modules. Your extension participates in that composition; it does not own the whole model or its method chain.

Guided practice

  1. Declare the owner module as a dependency.
  2. Use PoolMeta and the exact technical model name.
  3. Call super with compatible arguments and return semantics.
  4. Add only the smallest field or rule needed.
  5. Test with other modules that extend the same method.

Minimal example

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

class Party(metaclass=PoolMeta):
__name__ = 'party.party'
favorite_author = fields.Many2One(
'library.author', "Favorite Author")

@classmethod
def create(cls, vlist):
parties = super().create(vlist)
# Post-process only what this module owns.
return parties

# __init__.py
Pool.register(Party, module='library', type_='model')

How to read the example

Never copy a core class into your module to change one method. That freezes old behavior and bypasses other extensions. XML inheritance should target stable IDs and narrow XPath expressions.

Exercise

Extend party.party, add one field to its form, install another party extension, and prove both method chains execute.

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

Verifiable result

The extension disappears cleanly when the module is not activated and coexists with other installed extensions.

Common mistakes

  • omitting super
  • changing a public signature
  • depending on installation order instead of dependencies
  • replacing a complete core view

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 8.0 requires at least Python 3.10 according to official metadata. The official server declares its project with pyproject.toml; new modules should use modern packaging and verify wheel contents. Do not confuse this historical minimum with the Python version certified by your organization.

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