Make money with Oziconnect referral program

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

We are looking for someone with experience.
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

Counting lines of code in odoo-2's cloc-tool

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

Count the lines of code for cloc-tool in the odoo-usinf-config file

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

Count lines of code in a specific directory

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

Count lines of code in multiple directories

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 and static/tests.
  • Migration script defined in folder migrations and upgrades.
  • The XML file declared in demo or demo_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.

Make money with Oziconnect referral program
Make money with Oziconnect referral program
Make money with Oziconnect referral program
Make money with Oziconnect referral program
84512

About Us

We are a leading IT agency in Lagos, Nigeria, providing IT consulting and custom software development services. We offer a wide range of IT solutions across software development, web and mobile application development, blockchain development services, digital marketing, and branding.

Contact Us

25B Lagos-Abekouta Expressway Lagos

info@ozitechgroup.com

Phone: (234) 907 155 5545

@2023 OzitechGroup – All Right Reserved.