Step 1 uses odoo-bin shell to start the Odoo shell. All the usual command-line arguments are available. We use -c to specify a project configuration file and --log-level to reduce the verbosity of the logs. When debugging, you may want to have a logging level of DEBUG only for some specific addons.
Before providing you with a Python command-line prompt, odoo-bin shell starts an Odoo instance that does not listen on the network and initializes some global variables, which are mentioned in the output:
- env is an environment connected to the database specified on the command line or in the configuration file.
- odoo is the odoo package imported for you. You get access to all the Python modules within that package to do what you want.
- openerp is an alias for the odoo package for backward compatibility.
- self is a recordset of res.users containing a single record for the Odoo superuser (Administrator), which is linked to the environment env.
Steps 3 and 4 use env to get an empty recordset and find a record by XML ID. Step 5 calls the method on the product.product recordset. These operations are identical to what you would use inside a method, with the small difference that we use env and not self.env (although we can have both, as they are identical). Take a look at Chapter 6, Basic Server-Side Development, for more information on what is available.
Step 6 commits the database transaction. This is not strictly necessary here because we did not modify any record in database, but if we had done so and wanted these changes to persist, this is necessary; when you use Odoo through the web interface, each RPC call runs in its own database transaction, and Odoo manages these for you. When running in the shell mode, this no longer happens and you have to call env.cr.commit() or env.cr.rollback() yourself. Otherwise, when you exit the shell, any transaction in progress is automatically rolled back. When testing, this is fine, but if you use the shell, for example, to script the configuration of an instance, don't forget to commit your work!