Skip to Content

5 - The odoo-bin Command Line Interface (CLI) Masterclass

Welcome to the control room! If you want to become a truly professional Odoo developer, you cannot rely solely on the web interface. You need to master odoo-bin.

Think of odoo-bin as the steering wheel of your Odoo server. It is the core Python script that starts the framework, manages your databases, installs your code, and logs every action. Let’s break down the most important commands you will use every single day.

1. Starting the Engine (The Basics)

At its simplest, odoo-bin just needs to know where your configuration file is. This file (odoo.conf) tells the server which port to use, where your custom addons are, and how to connect to PostgreSQL.

To start your Odoo 19 server, navigate to your Odoo directory and run:

python3 odoo-bin -c odoo.conf

Note: The -c flag stands for "config". It points the server to your specific configuration file.


2. Managing Databases on the Fly

Sometimes, you want to bypass the web-based database manager and force Odoo to connect to a specific database immediately. You can do this using the -d (database) flag.

python3 odoo-bin -c odoo.conf -d my_test_database

💡 PRO TIP: If you want to build a brand new database completely from the terminal (without using the web interface), combine the -d flag with the -i base flag. This tells Odoo to create the database and install the foundational "base" module automatically:

python3 odoo-bin -c odoo.conf -d fresh_database -i base


3. The Developer's Best Friends: -i and -u

When you write new Python or XML code, Odoo doesn't just magically know about it. You have to tell the server to read your files and inject them into the database. This is where 90% of your CLI work happens.

Installing a New Module (-i): When you create a brand new module for the first time, use the -i (install) flag.

python3 odoo-bin -c odoo.conf -d my_database -i my_custom_module

Updating an Existing Module (-u): When you modify an XML view, add a new field to a Python model, or change security rules in a module that is already installed, you must use the -u (update) flag to apply those changes.

python3 odoo-bin -c odoo.conf -d my_database -u my_custom_module

You can update multiple modules at once by separating them with commas: -u sale,account,my_custom_module


4. Troubleshooting and Server Ports

What happens if you want to run two different Odoo instances at the same time? By default, Odoo runs on port 8069. If you try to run a second server, it will crash. You can easily override the port directly from the terminal using --xmlrpc-port.

python3 odoo-bin -c odoo.conf --xmlrpc-port=8070

Changing the Log Level: If your code is failing and Odoo isn't giving you enough information in the terminal, you can increase the logging detail to "debug" mode. This is incredibly helpful for finding hidden errors.

python3 odoo-bin -c odoo.conf --log-level=debug


5. The Hidden Gem: Odoo Shell

This is a secret weapon for senior developers. Instead of starting the web server, you can start an interactive Python terminal that is fully connected to your Odoo database.

It allows you to test ORM queries, check database records, and run Python code safely without writing a whole module.

To enter the Odoo shell, type:

python3 odoo-bin shell -c odoo.conf -d my_database

Once inside, you can interact directly with the database environment. For example, typing env['res.partner'].search([]) will immediately return a list of all your contacts!


6. A Quick Note on IDEs (PyCharm vs. Servers)

If you are using a powerful IDE like PyCharm Professional, you might notice that you don't have to type these commands manually. PyCharm has built-in run configurations where you can just put -u my_module in a text box and click a friendly green "Play" button to restart your server.

However, do not let this make you lazy! The moment you deploy your code to a live Ubuntu production server, or you need to SSH into a client's environment to troubleshoot a crashed database, those graphical buttons are gone. If you are dealing with a real server, you must know the CLI very well. Mastering odoo-bin is what separates a beginner from a true Odoo professional.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.