A collection of pre-commit hooks for Odoo projects, developed by Heligrafics S.L.
- odoo-method-order: Validates that methods and attributes in Odoo models follow a logical and predefined order to improve code readability and maintainability.
-
Install dependencies:
pip install .[test]
-
Install pre-commit in your repository:
pre-commit install
-
Run hooks manually (optional):
pre-commit run --all-files
-
The
odoo-method-orderhook/script accepts an optional--exit-zeroargument. If provided, the script will always return exit code 0, even if errors are found. This can be useful for CI or exploratory runs where you want to see warnings but not fail the pipeline. -
The script now reports all ordering errors found in a file, not just the first one. This helps to quickly identify and fix all method ordering issues in your Odoo models.
python src/hg_odoo_pre_commit_hooks/check_method_order.py --exit-zero path/to/your/model.py- Hooks are located in the
src/directory. - Automated tests are in the
tests/directory. - Example modules for testing are in
test_repo/.
You can run the tests with:
pytestOr using tox (to test in different environments):
toxsrc/: Source code for the hooks.tests/: Automated tests validating hook behavior.test_repo/: Example Odoo modules (both correct and intentionally incorrect) used in tests.method_ordered_module/: Example Odoo module with correctly ordered methods.method_not_ordered_module/: Example Odoo module with unordered methods to trigger errors.
.pre-commit-config.yaml: Pre-commit hook configuration..pre-commit-hooks.yaml: Local hook definitions.- Other configuration files:
.editorconfig,.ruff.toml,.pylintrc, etc.
- repo: https://github.com/heligrafics/odoo-pre-commit-hooks
rev: main
hooks:
- id: odoo-method-order- Create a branch for your feature or fix.
- Ensure all tests pass.
- Submit a pull request with a clear description of your contribution.
Heligrafics S.L.