How it works...

At startup, Odoo loads all the modules and combines the various classes that derive from Model, and also defines or extends the given model. These classes are stored in the Odoo registry, indexed by name. The env attribute of any recordset, available as self.env, is an instance of the Environment class defined in the odoo.api module.

This class plays a central role in Odoo development:

  • It provides shortcut access to the registry by emulating a Python dictionary. If you know the name of the model you're looking for, self.env[model_name] will get you an empty recordset for that model. Moreover, the recordset will share the environment of self.
  • It has a cr attribute, which is a database cursor you may use to pass raw SQL queries. Refer to the Executing raw SQL queries recipe in Chapter 9, Advanced Server-Side Development Techniques, for more on this.
  • It has a user attribute, which is a reference to the current user performing the call. Take a look at Chapter 9, Advanced Server-Side Development Techniques, and the Changing the user performing an action recipe for more on this.
  • It has a context attribute, which is a dictionary that contains the context of the call. This includes information about the language of the user, the timezone, the current selection of records, and much more. Refer to the Calling a method with a modified context recipe in Chapter 9, Advanced Server-Side Development Techniques for more on this.

The call to search() is explained in the Searching for records recipe later.

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

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