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 such as if you want to compute the results using sudo() or with a different user.

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

  • name is a string that contains the value the user has typed so far.
  • args is either None or a search domain that's 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() 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 whether operator is not 'ilike'. This is to avoid generating a dumb domain, [('name', ilike, '')], that doesn't filter anything. In this case, we jump straight to the super() call 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, in their ISBN, or in the author's names.
  4. Finally, we call the super() implementation with the modified domain in args and force the name to '' and the operator to ilike. We do this to force the default implementation of _name_search() to not alter the domain it receives, and so the one we specified will be used.
..................Content has been hidden....................

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