How it works...

Step 1 defines the method. Since we are not using the contents of self, we decorate it with @api.model, but this is not linked to the purpose of this recipe. Then, we get an empty recordset for the res.partner model because we need it to search the res.partner records.

Step 2 creates a search domain in a local variable. Often, you'll see this creation inlined in the call to search, but with complex domains, it is a good practice to define it separately.

For a full explanation of the search domain syntax, refer to the Defining filters on record lists: Domain recipe in Chapter 10, Backend Views.

Step 3 calls the search() method with the domain. The method returns a recordset containing all records matching the domain, which can then be further processed. In the recipe, we call the method with just the domain, but the following keyword arguments are
also supported:

  • offset=N: This is used to skip the N first records that match the query. This can be used along with limit to implement pagination or to reduce memory consumption when processing a very large number of records. It defaults to 0.
  • limit=N: Return at most N records. By default, there is no limit.
  • order=sort_specification: This is used to force the order on the returned recordset. By default, the order is given by the _order attribute of the model class.
  • count=boolean: If True, this returns the number of records instead of the recordset. It defaults to False.
We recommend using the search_count(domain) method rather than search(domain, count=True), as the name of the method conveys the behavior in a much clearer way; both will give the same result.
..................Content has been hidden....................

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