As every application , Odoo also comes with a set of cli commands that can be used to run and configure the Odoo. This is more useful for the developers. For this we have to clone any version of Odoo from git, i will be using the Odoo 9 as an example.
There are mainly 3 script files in the Odoo which are as follows
All of this file eventually run the main class of the Odoo
openerp.cli.main() and then start the
openerp.service.server.start which is the Odoo service using the configuration that we provided, if no configuration provided Odoo will run with the default configuration.
We can start the Odoo server with simply typing the
python odoo.py using the default configuration. We can supply additional flags to run Odoo as like the xmlrpc port and addons paths etc. To get all the possible flags for the Odoo cli we can run the command like
python odoo.py --help it will list all the possible flags that we can pass with the odoo.py . The list of all the flags can be found here.
Following are the most useful cli commands. Important thing to note here is Odoo loads the configuration in 3 steps. First loading the default configuration and second from the configuration file then last from the cli configuration that we supplied each time it will overwrite the previous one.
--stop-after-init tells Odoo to stop server after initialization. The main difference between the Odoo config file and the cli flags is missing hyphens in beginning and replacing all the hyphens in the middle with underscore for config file. Another interesting feature Odoo CLI is you can create a skeleton frame of your new module with sample codes. This is called scaffolding.
Odoo Shell Commands
As we do the test using the Odoo gui we can also do the same thing with the Odoo shell such as calling a function from the model etc. This is mostly for developers.
After running it, we will be inside a python command line prompt. In this we have access to certain Odoo keywords such as
openerp we can use the env for access any model from Odoo and execute any function behalf of it.
Important point to note is that when you are running in Odoo shell we have to commit the changes to the database using the database cursor, because in the Odoo GUI the database commits are handled by the Odoo itself.
Extra Debugging Methods By Python
There is a useful package in the python which is the
ipdb which can be used to find out what happens inside a function in the Odoo step wise.
ipdb stands for python debugger.
When python enters the function it will give you the ipdb console in the log with specifying the current execution line. You can list all the variables that you are using in the function by just typing the name. There is also wide variety of commands that you can use with the ipdb such as
n for next line and
c for continuing the execution.
ipdb is a nice tool for debugging python program's in real time.
The best way to understand is to practice every debugging methods that i explained here, so next time when an error occurs you know how to solve it.