When an Odoo module needs to hold a new kind of data, the developer defines a new model. This piece is about defining a new model in Odoo.
What a model is
A model, in Odoo, defines a kind of record, a kind of data the system holds. Almost everything in Odoo is built on models: a customer, an order, a product, each is a kind of record defined by a model. A model defines what a record of its kind is, in particular the fields, the pieces of information, that make up a record. When a developer needs the system to hold a new kind of data, the developer defines a new model for it.
Defining a new model
Defining a new model in Odoo is done in Python, in a module's models. A model is defined as a Python class, building on Odoo's model foundation, which gives it all that an Odoo model has. The model is given a name, its technical identifier, and it is given its fields, the definitions of the pieces of information a record of this kind holds. Defining the new model is, in essence, writing that class: declaring it as an Odoo model, naming it, and defining its fields.
The model is the foundation
Defining a new model is foundational, because the model is what everything else about the new kind of data is built on. Once the model is defined, records of that kind can exist; views can be built to present and edit those records; the records can be worked with through Odoo's data layer; security can govern access to them. All of that builds on the model. So defining the new model well, the right fields, properly defined, is the foundation for the new kind of data being genuinely usable. Defining the model is the first, foundational step of building new data-holding functionality.
Define the model to genuinely fit the data
An honest note. A new model should be defined to genuinely fit the kind of data it is for: the fields should be the genuine pieces of information that kind of record needs, properly defined, of the right kinds. A model defined thoughtfully, genuinely fitting the data, is a sound foundation; a model defined carelessly, with the wrong fields or fields of the wrong kinds, is a flawed foundation that undermines what is built on it. Defining a new model deserves the thought of genuinely modelling the kind of data it is for.
Work with the framework
Defining a new model, like all Odoo development, should be done the Odoo way, building on Odoo's model foundation, using Odoo's field definitions, following Odoo's conventions for how a model is defined. Odoo has an established way models are defined, and a model defined that way works properly within the framework and is maintainable. A developer defining a new model should do it within Odoo's conventions, working with the framework.
The takeaway
Defining a new model in Odoo is the developer's act of creating a new kind of record, done in Python, in a module's models, as a class building on Odoo's model foundation, named and given its fields. The model is the foundation that everything else about the new kind of data, the records, the views, the data access, the security, is built on, so define it thoughtfully to genuinely fit the data. Define a new model within Odoo's conventions, working with the framework. For how we approach Odoo, see our ERP practice.