There are scenarios where the web interface becomes inaccessible or perhaps you simply want to uninstall multiple modules at once. In such cases, uninstalling modules directly through the Command Line Interface (CLI) can be a powerful alternative.
In this post, we'll walk you through how to uninstall Odoo modules using the terminal, with a focus on doing it via PyCharm. However, this approach can be adapted to work with any CLI environment. We’ll demonstrate how to uninstall two modules: sale_management and project. Feel free to replace these with any modules you want to uninstall.
Setting Up a Python Run Configuration in PyCharm
If you're using PyCharm, create a new Python Run/Debug Configuration:
- Name: Choose something relevant like Uninstall Sale, Project apps.
- Interpreter: Select the correct Python interpreter
- Script: odoo-bin file or setup/odoo file
- Script Parameters:
shell -c <path_to_conf_file> -d <database_name>Ex: shell -c "/home/user/odoo.conf" -d demo-db
Running the Configuration
Once the configuration is set up:
- Click the Debug icon in PyCharm next to your new configuration.
- The PyCharm Debug Console will initialize and you’ll see >?
Executing the Uninstall Command
In the PyCharm Debug Console, execute the following code to uninstall the modules:
self.env['ir.module.module'].search([('name', 'in', ['sale_management', 'project'])]).button_immediate_uninstall()We can replace the list ['sale_management', 'project'] with any modules we want to uninstall.
With that command, the selected modules are now successfully uninstalled. Using the CLI to uninstall Odoo modules can save a lot of time, especially when dealing with corrupted modules or batch uninstallations.