OD205 field-type-changed¶
An inherited field is redefined with another type.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Correctness | Warning | all | yes |
What it reports¶
A class that extends a model declares a field the model already has, with another field type than
a class of the same model in this module or its dependencies gives it. A module that Odoo always
installs with base, such as web, counts as in depends.
Why it matters¶
Odoo merges every declaration of a field into one field of the type the last loaded declaration
gives it, so the type depends on which modules are installed and in what order. Every other module
that reads the field, shows it in a view or loads data into it was written for the original type.
When the type changes, Odoo converts the database column with a cast as the module installs or
updates: a cast PostgreSQL cannot make, such as text that is not a number into an integer, stops
the install, and one it can make drops what the new type cannot hold, such as the decimals of a
Float turned into an Integer.
The rule warns rather than fails because a few changes are deliberate, such as widening a Char
to a Text. Only classes of the same model are compared: a new model that takes a field from a
mixin through _inherit, or from a parent through _inherits, may give it any type.
Example¶
class ResPartner(models.Model):
_inherit = "res.partner"
ref = fields.Integer(string="Customer number")
ref is a Char in base, and its existing values do not all convert to integers.
class ResPartner(models.Model):
_inherit = "res.partner"
customer_number = fields.Integer()