Automate Odoo Code Quality. pre-commit Odoo apps automate code checks and lint workflows for Odoo modules, and then they help teams enforce standards consistently. Moreover, this tutorial walks you through setting up Odoo CI lint automation with GitHub Actions. Next, you will learn OCA pre-commit integration for pylint‑odoo and flake8‑odoo hooks. Furthermore, you will create a GitHub workflow to run pre-commit automatically on each push and pull request. Also, for more details, visit the official pre-commit docs at https://pre-commit.com.
source : https://github.com/odooerpdevelopers/mis-addons-public
Prerequisites for pre-commit Odoo apps
Odoo development environment setup
First, you install Odoo locally to test your modules, and then you clone your repo or the OCA add‑ons. Moreover, you verify that ./odoo-bin -c config.conf runs without errors. Next, you confirm that your database connection works by creating a demo database. Furthermore, you ensure that you can start the server and load a custom module successfully.
Python venv and dependencies
First, you create a Python virtual environment, and then you activate it. Moreover, you install or upgrade pip and setuptools. Next, you install pre-commit and basic tools in the venv. Furthermore, you freeze your requirements to requirements-dev.txt. Finally, you avoid version conflicts across your team.
python3 -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows PowerShell
pip install --upgrade pip setuptools
pip install pre-commit
pip freeze > requirements-dev.txt
Git configuration and clone
First, you install Git if you don’t have it, and then you set your user name and email. Moreover, you clone your Odoo repo or OCA add‑ons. Next, you navigate into the project folder. Furthermore, you verify a clean working tree with git status.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git clone https://github.com/your-org/your-odoo-repo.git
cd your-odoo-repo
git status
Installing pre-commit Odoo apps and OCA hooks
pip install pre-commit and enable hooks
First, you install pre-commit in your virtual environment, and then you verify its version. Moreover, you enable Git hooks by running pre-commit install. Next, you check that Git created .git/hooks/pre-commit. Finally, you confirm that the hook script runs before each commit.
pip install pre-commit
pre-commit --version # e.g., 2.20.0
pre-commit install
ls -l .git/hooks/pre-commit # ensure it is executable
Configuring .pre-commit-config.yaml for Odoo modules
First, you create .pre-commit-config.yaml at your repo root, and then you declare hook repos with pinned rev:. Moreover, you add basic pre-commit-hooks and OCA plugins. Next, you tune file patterns, args, and additional dependencies. Finally, you commit the config so that every team member inherits it.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/OCA/pylint-odoo
rev: 2.13.0
hooks:
- id: pylint-odoo
args: ["--rcfile=.pylintrc"]
- repo: https://github.com/OCA/flake8-odoo
rev: 15.0.0
hooks:
- id: flake8-odoo
additional_dependencies: ["flake8>=3.9.2"]
Automating Odoo code quality with GitHub Actions
Creating the pre-commit GitHub workflow
First, you add .github/workflows/pre-commit.yml to your repo, and then you configure triggers. Moreover, you choose ubuntu-latest and a specific Python version. Next, you check out code and install dependencies. Furthermore, you run pre-commit run --all-files to enforce checks on every PR and push. Automate Odoo Code Quality.
# .github/workflows/pre-commit.yml
name: CI / pre-commit checks
on:
push:
branches:
- '18.0'
- '19.0'
pull_request:
paths:
- '**/*.py'
- '.pre-commit-config.yaml'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m venv .venv
source .venv/bin/activate
pip install pre-commit
- name: Run pre-commit hooks
run: pre-commit run --all-files
Caching Python packages in CI
First, you add caching to speed up installs, and then you reuse pip cache across jobs. Moreover, you configure actions/cache@v3 before installing dependencies. Next, you verify that cache hits reduce workflow time. Finally, you maintain fresh dependencies by updating cache keys.
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
pylint‑odoo pre‑commit hook setup
Creating .pylintrc for Odoo checks
First, you add a .pylintrc file at the root, and then you load pylint_odoo plugin. Moreover, you disable docstring warnings you don’t need. Next, you set your target Odoo version. Finally, you commit .pylintrc to enforce consistent lint rules.
# .pylintrc
[MASTER]
load-plugins=pylint_odoo
[MESSAGES CONTROL]
disable=C0114,C0115,C0116 # skip missing docstrings
[ODOO]
version=16.0
Explaining pylint-odoo options
First, load-plugins tells Pylint to use OCA’s plugin, and then it checks manifest, model naming, and translations. Moreover, disable silences specific messages, and then you tailor it to your style. Next, the [ODOO] block sets Odoo’s version so that rules match your platform. Finally, you keep .pylintrc under version control for team consistency.
flake8‑odoo pre‑commit hook setup
Creating flake8.cfg for style enforcement
First, you create flake8.cfg at the root, and then you configure line length and exclusions. Moreover, you pick error codes to enforce, and then you ignore known false positives. Next, you commit flake8.cfg to share style rules. Finally, pre-commit picks it up via the --config arg.
# flake8.cfg
[flake8]
max-line-length = 100 exclude = .git, __pycache__, .venv, tests/fixtures select = C,E,F,W,B,B950 ignore = F403,F405
Extending pre-commit Odoo apps with additional hooks
Adding ruff‑odoo for faster lint
First, you include the ruff-odoo hook, and then you pin its rev: in .pre-commit-config.yaml. Moreover, you add any extra dependencies via additional_dependencies. Next, you tune file patterns or args. Finally, you test ruff alongside existing hooks.
- repo: https://github.com/charliermarsh/ruff
rev: v0.0.278
hooks:
- id: ruff
args: ["--select", "E,F,W"]
additional_dependencies:
- ruff-odoo>=0.0.4
Defining local hooks for custom checks
First, you create shell or Python scripts under scripts/, and then you add them as repo: local. Moreover, you define entry, language, and args. Next, you commit the scripts alongside the config. Finally, pre-commit runs them like any other hook.
- repo: local
hooks:
- id: check-manifest
name: Check Odoo manifest
entry: bash scripts/check_manifest.sh
language: system
types: [python]
exclude: docs/
Best practices for OCA pre-commit integration
Pinning hook versions for stability
First, you pin each hook to a specific rev:, and then you upgrade locks in controlled intervals. Moreover, you avoid unexpected failures by testing new versions in a feature branch. Next, you merge after CI passes. Finally, you document update dates in your changelog. Automate Odoo Code Quality.
Reusing YAML anchors to reduce duplication
First, you define shared settings under an anchor, and then you merge them via <<:. Moreover, you keep .pre-commit-config.yaml DRY. Next, you maintain a single source for file patterns and excludes. Finally, you reduce config drift across multiple hooks.
defaults: &defaults
files: \.py$
exclude: tests/fixtures/
repos:
- repo: https://github.com/OCA/pylint-odoo
rev: 2.13.0
hooks:
- id: pylint-odoo
<<: *defaults
- repo: https://github.com/OCA/flake8-odoo
rev: 15.0.0
hooks:
- id: flake8-odoo
<<: *defaults
Documenting setup in CONTRIBUTING.md
First, you add a CONTRIBUTING.md that guides new contributors through pre-commit setup. Moreover, you include install steps, commands to run hooks manually, and how to bypass with --no-verify. Next, you link to official docs and your customized configs. Finally, you keep on-boarding friction low.
Troubleshooting pre-commit Odoo apps issues
Fixing hook installation errors
First, you check file permissions on .git/hooks/pre-commit, and then you set chmod +x. Moreover, you verify your Git version supports hooks. Next, you reinstall with pre-commit install --overwrite. Finally, you test a dummy commit to confirm.
Resolving CI failures in GitHub Actions
First, you read the workflow logs under “Actions”, and then you locate hook errors. Moreover, you adjust files: or exclude: patterns if hooks misfire. Next, you add missing dependencies or correct versions. Finally, you re-run the workflow after pushing fixes.
Speeding up slow hook runs
First, you limit hooks to staged files via pre-commit run --hook-stage commit. Moreover, you split heavy checks to CI only. Next, you cache Python packages and use warm runners. Finally, you profile hooks to identify bottlenecks.
Conclusion: Mastering pre-commit Odoo apps
First, integrating pre-commit Odoo apps and OCA plugins streamlines Odoo CI lint automation. Moreover, embedding hooks into GitHub Actions ensures consistent quality on every push and pull request. Next, following best practices like pinning versions and documenting setup fosters team collaboration. Finally, you free developers from manual checks so they can focus on building features and delivering robust Odoo apps.
Discover more from teguhteja.id
Subscribe to get the latest posts sent to your email.

