OD106 name-get-deprecated¶
name_get() is ignored; override _compute_display_name().
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Deprecation | Warning | 17.0 and later | no |
What it reports¶
A model class that defines a name_get() method, in a module of series 17.0 or later.
Why it matters¶
From 17.0, the name Odoo shows for a record is the computed field display_name, and
_compute_display_name() fills it. The ORM and the web client no longer call name_get(), so an
override of it raises no error and changes nothing: many2one fields, breadcrumbs and search
results keep showing the default name. In 17.0, name_get() survives only as a deprecated method
that reads display_name; from 18.0 it is gone, so code that still calls it raises
AttributeError. Such calls are not reported by this rule.
Modules of earlier series are not checked, since name_get() is the right method there. Put the
fields the name reads in @api.depends, so the name is recomputed when they change.
Example¶
class ResPartner(models.Model):
_inherit = "res.partner"
def name_get(self):
return [(partner.id, f"{partner.name} [{partner.ref}]") for partner in self]
Nothing calls this method from 17.0, so partners keep their plain name.
class ResPartner(models.Model):
_inherit = "res.partner"
@api.depends("name", "ref")
def _compute_display_name(self):
for partner in self:
partner.display_name = f"{partner.name} [{partner.ref}]"