Skip to content

Add Models and Fields

rafageist edited this page Nov 30, 2026 · 1 revision

Add Models and Fields

Two wizards change an existing module: File > Add model to module and File > Add fields to model (also in the Explorer's local menu, on a module, a model's file or a class). Both show every change as a diff before Apply.

Add fields: a Date and a Many2one, the diff to the model and its views, Apply

Add model to module

A new model (_name) or an extension of an existing one (_inherit; Models... lists the models of the module's dependencies when their folders are found, otherwise type the name). It creates models/<model>.py, adds its import to models/__init__.py, and for a new model adds the access row (Odoo 19 ir.model.access.csv, Odoo 20 ir.access.csv, the series read from the manifest's version) and, optionally, views, an action and a menu under the module's top menu; the manifest's data gets the new files.

Add model to module

Its diff

Add fields to model

Char, Text, Integer, Float, Boolean, Date, Datetime, Selection, Many2one, One2many (with its inverse), Many2many, related, and computed with an @api.depends method stub. Type a field and Add field keeps it and empties the form for the next one; Preview shows them all. They go after the class's last field and, optionally, after the last field of the model's form and list views when the module has exactly one of each (otherwise the preview says they were left alone).

Add fields to model

Its diff

What Apply promises

  • Edits are minimal: a line appended, an entry inserted, lines after a located field. They are computed from the files' text and parsed again (ast for Python, ElementTree for XML, CSV, literal_eval for the manifest) before anything is shown.
  • A file that cannot be edited exactly, such as a manifest whose data is not a written list, is refused with the reason.
  • Apply writes only if every file is still byte-identical to the preview, and saves each edited file atomically. A file with unsaved changes in an editor stops it; open editors show the new text.

Clone this wiki locally