O'Reilly logo

Odoo Development Cookbook by Daniel Reis, Alexandre Fayolle, Holger Brunn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Customizing how records are searched

The Defining the Model representation and order recipe in Chapter 3, Creating Odoo Modules introduced the name_get() method, which is used to compute a representation of the record in various places, including in the widget used to display Many2one relations in the web client.

This recipe shows how to allow searching for a book in the Many2one widget by title, author, or ISBN by redefining name_search.

Getting ready

For this recipe, we will be using the following model definition:

class LibraryBook(models.Model): _name = 'library.book' name = fields.Char('Title') isbn = fields.Char('ISBN') author_ids = fields.Many2many('res.partner', 'Authors') @api.model def name_get(self): result = [] for book in self: authors ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required