Skip to main content

Display Another Field in Many2one Instead of Name In Odoo

In Odoo, you can display a custom field in the many2one widget instead of the default object’s name field. This can be helpful if you want to display different information in the widget than what is displayed in the standard field.¬†You can use this feature to customize your views and reports or to make it easier for your users to find information on their records.

Below is a snippet of appending Internal Note field to a product.

class ProductTemplate(models.Model):
    _inherit = 'product.template'

    def name_get(self):
        self.browse(self.ids).read(['name', 'default_code', 'description'])
        return [(, '%s%s%s' % (template.default_code and '[%s] ' % template.default_code or '',, template.description and ' (%s)' % template.description or ''))
                for template in self]

Show respecrtive category name depends on other fields of a custom model

    def name_get(self):
        # show category by name or complete_name
        res = []
        for category in self:
            if 'complete_name' in self._fields:
                res.append((, category.complete_name))

        return res

By continuing to use the site, you agree to the use of cookies.