Customizing how records are searched
The Defining the model representation and order recipe in Chapter 3, Creating Odoo Add-On Modules, introduced the name_get()
method, which is used to compute a representation of the record in various places, including in the widget that's used to display Many2one
relations in the web client.
This recipe will show you how to search for a book in the Many2one
widget by title, author, or ISBN by redefining name_search
.
Getting ready
For this recipe, we will use 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') Â Â Â Â def name_get(self): Â Â Â Â Â Â Â Â result = [] Â Â Â Â ...