Customizing how records are searched
The Defining the model representation and order tutorial 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 tutorial will show you how to search for a room in the Many2one
widget by room number and name by redefining name_search
.
Getting ready
For this tutorial, we will use the following model definition:
class HostelRoom(models.Model): Â Â Â Â def name_get(self): Â Â Â Â Â Â Â Â result = [] Â Â Â Â Â Â Â Â for room in self: Â Â Â Â Â Â Â Â Â Â Â Â member = room.member_ids.mapped('name') Â Â Â Â Â Â Â Â Â Â Â Â name = '%s (%s)' % (room.name, &apos...