Custom pre-commit hooks for Odoo module validation with comprehensive documentation coverage analysis. Catches errors and runtime warnings before starting the server.
Supports Odoo 17.0, 18.0, and 19.0 with automatic version detection.
| Odoo Version | Python | Status |
|---|---|---|
| 17.0 | 3.10+ | ✅ Fully Supported |
| 18.0 | 3.10+ | ✅ Fully Supported |
| 19.0 | 3.11+ | ✅ Fully Supported |
# Clone solt-pre-commit
git clone https://github.com/soltein-net/solt-pre-commit.git
# Setup your Odoo repository (auto-detects version)
python solt-pre-commit/setup-repo.py /path/to/your-odoo-repo
# Or specify version explicitly
python solt-pre-commit/setup-repo.py /path/to/your-odoo-repo --odoo-version 18.0
# Batch setup multiple repos
python solt-pre-commit/setup-repo.py --batch repos.txt
# Done! The script creates all necessary filesAdd to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/soltein-net/solt-pre-commit
rev: v1.0.1 # Supports Odoo 17.0, 18.0, 19.0
hooks:
- id: solt-check-branch
- id: solt-check-odooInstall and run:
pip install pre-commit
pre-commit install
pre-commit run --all-files| Check Type | Description | Blocks PR |
|---|---|---|
| Branch Names | Enforces naming conventions | ✅ |
| Odoo Runtime Warnings | Detects issues before server start | ✅ |
| XML Validations | Syntax, duplicates, deprecations | ✅ |
| Python Quality | Docstrings, field attributes | Configurable |
| CSV/PO Files | Duplicate IDs, translation errors | ✅ |
| Documentation Coverage | Detailed reports with trends | ℹ️ Informative |
# .solt-hooks.yaml
validation_scope: changed # or 'full'
severity:
python_field_missing_string: warning
python_method_missing_docstring: warning
skip_docstring_methods:
- create
- writeUse our reusable GitHub Actions workflow:
# .github/workflows/validate.yml
jobs:
validate:
uses: soltein-net/solt-pre-commit/.github/workflows/[email protected]
with:
validation-scope: 'changed'
fail-on-warnings: false| Hook ID | Description | Use Case |
|---|---|---|
solt-check-branch |
Branch naming validation | All repos |
solt-check-odoo |
Full module validation | Primary hook |
solt-check-xml |
XML files only | Targeted checks |
solt-check-csv |
CSV files only | Data validation |
solt-check-po |
Translation files only | i18n checks |
solt-check-python |
Python files only | Code quality |
Catches these Odoo warnings before they appear in your logs:
| Odoo Warning | Check Name |
|---|---|
Two fields have the same label |
python_duplicate_field_label |
inconsistent 'compute_sudo' |
python_inconsistent_compute_sudo |
tracking value will be ignored |
python_tracking_without_mail_thread |
selection attribute will be ignored |
python_selection_on_related |
Using active_id is deprecated |
xml_deprecated_active_id_usage |
Alert must have role |
xml_alert_missing_role |
🐍 Python Checks
python_duplicate_field_label- Same label on multiple fieldspython_inconsistent_compute_sudo- Inconsistent compute_sudopython_tracking_without_mail_thread- tracking without inheritancepython_selection_on_related- Selection on related fields
python_field_missing_string- Fields without string attributepython_field_missing_help- Fields without help textpython_method_missing_docstring- Methods without docstringpython_docstring_too_short- Docstrings < 10 charspython_docstring_uninformative- Generic docstrings
📄 XML Checks
xml_syntax_error- XML parse errorsxml_duplicate_record_id- Duplicate record IDsxml_duplicate_fields- Duplicate field definitionsxml_deprecated_active_id_usage- Deprecated active_id usagexml_alert_missing_role- Alert without role attribute
xml_deprecated_tree_attribute- Deprecated tree attributesxml_hardcoded_id- Hardcoded IDs instead of ref()xml_create_user_wo_reset_password- User creation issuexml_dangerous_filter_wo_user- Filter without user_id
📊 CSV Checks
csv_syntax_error- CSV parse errorscsv_duplicate_record_id- Duplicate XML IDs
🌐 PO/POT Checks
po_syntax_error- Translation file errorspo_duplicate_message_definition- Duplicate translationspo_requires_module- Missing module commentpo_python_parse_printf- Printf variable errorspo_python_parse_format- Format string errors
Configure the Odoo version (auto-detected by default):
# .solt-hooks.yaml
odoo_version: auto # Auto-detect from manifest (default)
# odoo_version: 17.0 # Force specific version
# odoo_version: 18.0
# odoo_version: 19.0Or via command line:
solt-check-odoo /path/to/module --odoo-version 18.0Or via environment variable:
export SOLT_ODOO_VERSION=18.0
solt-check-odoo /path/to/moduleControl what gets validated:
# .solt-hooks.yaml
validation_scope: changed # Only validate modified files (recommended for legacy)
# validation_scope: full # Validate all files# .solt-hooks.yaml
severity:
# Make docstring checks non-blocking
python_method_missing_docstring: info
python_docstring_too_short: info
# Make field attributes blocking
python_field_missing_string: error# .solt-hooks.yaml
skip_string_fields:
- active
- name
- sequence
skip_help_fields:
- active
- name
skip_docstring_methods:
- create
- write
- unlinkOdoo version prefix is REQUIRED in all branch names:
branch_naming:
strict: true # Requires version + ticket: feature/17.0-SOLT-123-description
# strict: false # Requires version: feature/17.0-description
ticket_prefixes:
- SOLT
- PROJ
allowed_types:
- feature
- fix
- hotfix
- bugfix
- release
- refactor
- docs
- test
- chore
- imp
- perf
- ci
- deps
- securityValid examples:
feature/17.0-SOLT-123-add-invoice✅ (recommended)fix/18.0-PROJ-456-fix-bug✅feature/17.0-add-new-feature✅ (flexible mode)hotfix/18.0-urgent-fix✅release/17.0.1.0✅
Invalid (missing version):
feature/add-something❌feature/SOLT-123-something❌
# Validate module
solt-check-odoo /path/to/module
# Force full validation (ignore scope config)
solt-check-odoo /path/to/module --scope full
# Show info-level issues
solt-check-odoo /path/to/module --show-info
# Validate branch name
solt-check-branch feature/SOLT-123-my-featureThe setup-repo.py script provides multiple operation modes:
# Single repo
python setup-repo.py /path/to/repo
# Batch setup
python setup-repo.py --batch repos.txt
# With options
python setup-repo.py /path/to/repo --scope full --odoo-version 18.0# Update solt-pre-commit version in .pre-commit-config.yaml
python setup-repo.py --update-only /path/to/repo
python setup-repo.py --update-only --batch repos.txt
python setup-repo.py --update-only --batch repos.txt --version v1.0.2# Clean global pre-commit cache
python setup-repo.py --clean
# Reinstall hooks in repos
python setup-repo.py --reinstall-hooks /path/to/repo
python setup-repo.py --reinstall-hooks --batch repos.txt
# Run autoupdate for solt-pre-commit
python setup-repo.py --autoupdate /path/to/repo
python setup-repo.py --autoupdate --batch repos.txtpython setup-repo.py --helpsolt-pre-commit/
├── .github/
│ └── workflows/
│ ├── ci.yml # Internal CI pipeline
│ ├── solt-update-badges.yml # Weekly badge updates
│ └── solt-validate.yml # Reusable workflow for clients
├── src/
│ └── solt_pre_commit/
│ ├── __init__.py # Package exports
│ ├── checks_branch_name.py # Branch naming validation
│ ├── checks_odoo_module.py # Main orchestrator
│ ├── checks_odoo_module_csv.py # CSV validations
│ ├── checks_odoo_module_po.py # PO/POT validations
│ ├── checks_odoo_module_python.py # Python validations
│ ├── checks_odoo_module_xml.py # Basic XML validations
│ ├── checks_odoo_module_xml_advanced.py # Advanced XML checks
│ ├── config_loader.py # Configuration management
│ └── doc_coverage.py # Documentation coverage analysis
├── setup-repo.py # Initialize/maintain client repos
├── _pylintrc # Pylint configuration for Odoo
├── _solt-hooks.yaml # Default hook settings
├── _pre-commit-config.yaml # Pre-commit template (GitHub)
├── _pre-commit-config-local.yaml # Pre-commit template (local/monorepo)
├── .pre-commit-hooks.yaml # Hook definitions for consumers
├── pyproject.toml # Package configuration
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
└── README.md
# From solt-pre-commit directory
python setup-repo.py ../your-repo
# With options
python setup-repo.py ../your-repo --scope full --dry-run
# Batch setup multiple repos
python setup-repo.py --batch repos.txtThis creates:
.pre-commit-config.yaml- Hook configuration.solt-hooks.yaml- Validation settings.pylintrc- Pylint rulespyproject.toml- Python tools config (Ruff, etc.).github/workflows/solt-validate.yml- CI workflow
python setup-repo.py ../solt-addons --localUses local Python paths instead of GitHub URLs.
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=solt_pre_commit --cov-report=html# Install package locally
pip install -e .
# Create test module
mkdir -p test_module
cat > test_module/__manifest__.py << 'EOF'
{
"name": "Test Module",
"version": "17.0.1.0.0",
"depends": ["base"],
"installable": True,
}
EOF
# Run validation
solt-check-odoo test_moduleLGPL-3.0-or-later
Contributions welcome! Please:
- Fork the repository
- Create a feature branch:
feature/17.0-ISSUE-123-description(version + ticket recommended) - Ensure all checks pass:
pre-commit run --all-files - Create a Pull Request
See CONTRIBUTING.md for detailed guidelines.
- Issues: GitHub Issues
- Email: [email protected]
Developed by Soltein SA de CV