This article provides an overview of how to use Odoo’s CLOC tool as a developer.
Before starting this tutorial, you should understand the basic concepts of Odoo’s CLI. If you don’t have basic knowledge of Odoo CLI, read the Odoo CLI beginner’s guide.
Why is CLOC tool required for Odoo CLI?
- Odoo’s CLOC tool helps you count the number of related lines written in Python, JavaScript, CSS, SCSS, or XML.
- Counting lines of code helps you estimate the effort required to maintain, debug, and further develop your Odoo customizations.
- Helps you understand the size and complexity of your codebase.
Before you move on, check out our Odoo development services and wide range of high-quality Odoo apps..
How can I use CLOC tool with Odoo CLI?
1.) Count lines of code using addon paths
Lines of code from all modules or directories present in the add-on path are counted.
syntax
Odu Company? read more
odoo-bin cloc --addons-path=addons -d my_database
Here is the command to count the number of lines of code that contain add-on paths:
./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, “.” represents the current directory. “-d” or “-Database” indicates the database name. Also, if you use “-d” or “-Database” That way it only counts lines of code for installed modules.
Note:- When using add-on paths to count lines of code. Then you should use db_user, db_password, db_host etc. if available in the Odoo configuration file.
Upper command output
This is a command that counts paths and lines of code for add-ons. -v or –Redundant.
./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” Used to display details of rows counted per file.
output just like this
2.) Count lines of code of setting file
Lines of code from all modules or directories present in the add-on path are counted.
Learn how to perform database operations using Odoo CLI.
syntax
odoo-bin cloc -c config.conf -d my_database
The command to count lines of code is: setting file.
./opt/odoo/odoo-bin cloc -c /etc/odoo/odoo-server.conf -d extra-fee-check
Here we are passing the path of the custom configuration file as follows: “-c”.
output
Note:- You can also use “-v” or “-redundant” with the command above.
3.) Count the lines of code of module or directory path
Counts the lines of code for a specific module or directory in the add-on path.
syntax
odoo-bin cloc -p addons/account
Below is the command to count the lines of code. single module.
./opt/odoo/odoo-bin cloc -p /opt/odoo-custom-addons/variant_price_extra
where, “-p” or “-path” indicates the add-on path.
output
Here’s another command to count lines of code: multiple modules.
syntax
odoo-bin cloc -p addons/account -p addons/sale
The code is as follows
./opt/odoo/odoo-bin cloc -p /opt/odoo-custom-addons/variant_price_extra -p /opt/odoo-custom-addons/odoo_magento_connect
output
Note:- You can also use “-v” or “-redundant” with the command above.
Some files are excluded from the count by default.
- Manifest (
__manifest__.py
or__openerp__.py
). - Folder contents
static/lib
. - Tests defined within the folder
tests
andstatic/tests
. - Migration script defined in folder
migrations
andupgrades
. - The XML file declared in
demo
ordemo_xml
Manifest section.
How to exclude custom files and directories (modules) from counting:
This can be done in the following way: cloc_exclude
Manifest file entries.
here it is syntax for 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 ]
pattern "**/*
” allows you to ignore an entire module. This is useful if you want to exclude modules from maintenance service costs. like,
"cloc_exclude": [ "**/*", # exclude a module ]
Need help?
We hope you find this guide helpful. Please feel free to share your feedback in the comments section below.
If you still have issues or questions regarding this, please open a ticket at the UV desk.
If you have any questions, please contact our support email.