Default Values in Odoo Models

When a record is created, some fields can start with a default value. How default values work in Odoo.

When a new record is created, its fields start out needing values. Some can start with a sensible default. This piece is about default values in Odoo models.

What a default value is

A default value is the value a field starts with when a new record is created. Rather than the field starting empty, awaiting a value, it starts with the default, a sensible starting value. The default is, in effect, the value the field has by default, which can then be kept, if the default is what is wanted, or changed, if it is not. A developer defining a model can give a field a default value.

Why default values are useful

Default values are useful because, for many fields, there is a value that is the common, sensible starting point, the value the field will, much of the time, genuinely have. Giving such a field that value as its default means that, when a record is created, the field already has the common value, and it does not have to be entered. For the common case, the default is right and nothing needs doing; for the less common case, the default is changed. So default values reduce the entry needed when creating records, the common-case fields are already filled with the right value, and they also help correctness, the common value is there by default rather than being something that has to be remembered and entered each time.

What makes a good default

The practical point for a developer is that a default value should be a genuinely sensible default for the field, the value that is genuinely the common, right starting point. A good default is one that is, much of the time, genuinely what the field should be, so it is right by default for the common case. A default that is not genuinely the common case is not a good default; it just puts a value there that often has to be changed, which is no help and could even cause the wrong value to be kept by mistake. A developer should give a field a default value where there is a genuinely sensible common default, and choose that genuine common value as the default.

Default values fit common cases, not all

An honest note. A default value serves the common case; it is not meant to be right for every case. The default is the sensible common starting point, and where a particular record's field should genuinely be something else, the default is changed. A developer should not expect a default to be right always; the point of a default is to be right for the common case, reducing entry and helping correctness there, while the less common cases are handled by changing it. A good default is a good common starting point, not a claim to be always right.

The takeaway

Default values in Odoo models give a field a sensible starting value when a record is created, so the field starts with the default rather than empty. They are useful because, for many fields, there is a common, sensible starting value, and the default means the common-case field is already filled with the right value, reducing entry and helping correctness. A good default is a genuinely sensible common value; a developer should set defaults where there is one, and choose the genuine common value, while less common cases are handled by changing it. For how we approach Odoo, see our ERP practice.

All posts

Got a Topic Worth Posting?

Suggest a Topic

If a question keeps coming up in your operations, it might be worth its own post.