How to do it...

To be able to search for a library.book either by the book's title, one of the authors, or the ISBN number, you need to define the _name_search() method in the LibraryBook class, as follows:

 @api.model 
 def _name_search(self, name='', args=None, operator='ilike', 
                  limit=100, name_get_uid=None): 
     args = [] if args is None else args.copy() 
     if not(name == '' and operator == 'ilike'): 
         args += ['|', '|', 
                  ('name', operator, name), 
                  ('isbn', operator, name), 
                  ('author_ids.name', operator, name) 
                  ] 
     return super(LibraryBook, self)._name_search( 
         name=name, args=args, operator=operator, 
         limit=limit, name_get_uid=name_get_uid) 

Add the old_editions Many2one field in the library.book model to test the _name_search implementation:

old_edition = fields.Many2one('library.book', string='Old Edition')

Add the following field to the user interface:

<field name="old_edition" />

Restart and update the module to reflect these changes. You can invoke the _name_search method by searching in the old_edition Many2one field.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset