This article gives an overview of how we can work with the CLOC tool in Odoo as a developer.
Before starting this tutorial, you should have a basic idea of CLI in Odoo. If you don’t have basic knowledge of Odoo CLI, read a beginner guide to Odoo CLI.
Why do we need CLOC Tool in Odoo CLI?
- CLOC Tool in Odoo helps to count the number of relevant lines written in Python, Javascript, CSS, SCSS, or XML.
- Counting lines of code can help you estimate the effort required for maintenance, debugging, and further development of your Odoo customization.
- It helps in understanding the size and complexity of a codebase.
Before moving ahead, check out our Odoo development services & an extensive range of quality Odoo Apps.
How to use the CLOC Tool in Odoo CLI?
1.) Counting the lines of code with addons path
It will count the lines of code for all the modules or directories that are present in the add-ons path.
Syntax
odoo-bin cloc --addons-path=addons -d my_database
Here is the command for counting the lines of code with addons path.
./opt/odoo/odoo-bin cloc --addons-path=/opt/odoo-custom-addons -d extra-fee-check --db_host=localhost --db_user=odoo --db_password=odoo
Where, “.” denotes the current directory. “-d” or “–database” denotes the database name, and also if we use “-d” or “–database” then it will count the lines of code only for installed modules.
Note:- If we use an add-ons path for counting the lines of code. Then, we need to use db_user, db_password, db_host, etc.. if available in your Odoo config file.
Output for upper command

Here is the command for counting the lines of code with addons path and -v or –verbose.
./opt/odoo/odoo-bin cloc --addons-path=/opt/odoo-custom-addons -d extra-fee-check --db_host=localhost --db_user=odoo --db_password=odoo -v or ./opt/odoo/odoo-bin cloc --addons-path=/opt/odoo-custom-addons -d extra-fee-check --db_host=localhost --db_user=odoo --db_password=odoo --verbose
Where, “-v” or “–verbose” is used to show the details of lines counted for each file.
Output just like this

2.) Counting the lines of code with the config file
It will count the lines of code for all the modules or directories that are present in the add-ons path.
Learn how to perform database operations using Odoo CLI.
Syntax
odoo-bin cloc -c config.conf -d my_database
Here is the command for counting the lines of code with the config file.
./opt/odoo/odoo-bin cloc -c /etc/odoo/odoo-server.conf -d extra-fee-check
Here we have passed our custom config file path using “-c”.
Output

Note:- We can also use the “-v” or “–verbose” in the upper commands.
3.) Counting the lines of code with the path of the module or directory
It will count the lines of code for particular modules or directories that are present in the add-ons path.
Syntax
odoo-bin cloc -p addons/account
Here is the command for counting the lines of code for a single module.
./opt/odoo/odoo-bin cloc -p /opt/odoo-custom-addons/variant_price_extra
Where, “-p” or “–path” denotes the add-ons path.
Output

Here is another command for counting the lines of code for multiple modules.
Syntax
odoo-bin cloc -p addons/account -p addons/sale
Here is the code
./opt/odoo/odoo-bin cloc -p /opt/odoo-custom-addons/variant_price_extra -p /opt/odoo-custom-addons/odoo_magento_connect
Output

Note:- We can also use the “-v” or “–verbose” in the upper commands.
Some files are excluded from the count by default:
- The manifest (
__manifest__.py
or__openerp__.py
). - The contents of the folder
static/lib
. - The tests defined in the folder
tests
andstatic/tests
. - The migration scripts defined in the folder
migrations
andupgrades
. - The XML files declared in the
demo
ordemo_xml
sections of the manifest.
How to exclude the custom files and directories(modules) from the count:
This can be done by the cloc_exclude
entry in the manifest file.
Here is the syntax of cloc_exclude:
"cloc_exclude": [ "lib/common.py", # exclude a single file "data/*.xml", # exclude all XML files in a specific folder "example/**/*", # exclude all files in a folder hierarchy recursively "**/*.scss", # exclude all scss file from the module ]
The pattern "**/*
” can be used to ignore an entire module. This can be useful to exclude a module from maintenance service costs. Like as,
"cloc_exclude": [ "**/*", # exclude a module ]
NEED HELP?
Hope you find the guide helpful! Please feel free to share your feedback in the comments below.
If you still have any issues/queries regarding the same, please raise a ticket at the UV Desk.
For any doubt, contact us at our support mail.