



Recommend: How to override functions/methods in odoo

Code:



1@api.model

2def name_search(self, name, args=None, operator='ilike', limit=100):

3 args = args or []

4 recs = self.browse()

5 if not recs:

6 recs = self.search([('subject_id', operator, name)] + args, limit=limit)

7 return recs.name_get()



Description:



Here we override "name_search" builtin method of Odoo. And in line no 7 we searched on "subject_id" instead of name.





1@api.model2def name_search(self, name, args=None, operator='ilike', limit=100):3 args = args or []4 recs = self.browse()5 if not recs:6 recs = self.search([('subject_id', operator, name)] + args, limit=limit)7 return recs.name_get()Here we override "name_search"builtin method of Odoo. And in line no 7 we searched on "subject_id" instead of name.

We know that in Odoo search is available by default on "name" field. For example here is many2one field named "section". And we are enable to search on those field because this field is the combination of two field subject name and section name.We can enable search on many2one fields by other than "name" field. We can achieve this by overriding "name_search" method of Odoo.