How it works...

The default implementation of name_search() actually only calls the _name_search() method, which does the real job. This _name_search() method has an additional argument, name_get_uid, which is used in some corner cases to compute the results using sudo().

We pass most of the arguments that we receive unchanged to the super() implementation of the method:

  • name is a string containing the value the user has typed so far.
  • args is either None or a search domain used as a prefilter for the possible records (it can come from the domain parameter of the Many2one relation, for instance).
  • operator is a string containing the match operator. Generally, you will have 'ilike' or '='.
  • limit is the maximum number of rows to retrieve.
  • name_get_uid can be used to specify a different user when calling name_get() in the end to compute the strings to display in the widget.

Our implementation of the method does the following:

  1. It generates a new empty list if args is None, and makes a copy of args otherwise. We make a copy to avoid our modifications to the list having side effects on the caller.
  2. Then, we check whether name is not an empty string or if operator is not 'ilike'. This is to avoid generating a dumb domain [('name', ilike, '')] that does not filter anything. In this case, we jump straight to the call to the super() implementation.
  3. If we have a name, or if the operator is not 'ilike', then we add some filtering criteria to args. In our case, we add clauses that will search for the supplied name in the title of the books, or in their ISBN, or in the author's names.
  4. Finally, we call the super() implementation with the modified domain in args and force name to '' and operator to ilike. We do this to force the default implementation of _name_search() to not alter the domain it receives, so the one we specified is to be used.
..................Content has been hidden....................

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