Availability |
Odoo Online
Odoo.sh
On Premise
|
Lines of code | 78 |
Technical Name |
hook_model_methods |
License | LGPL-3 |
Hook Model Methods

📢 Available for Hire!
Looking for a skilled and reliable Odoo Developer to bring your business ideas to life? or to fix things? or to analyze unwanted results? or to do whatever in odoo
Let’s build something great together! I specialize in custom module development, ERP implementation, and performance tuning tailored to your needs.
📬 Hire Me wa.me/923482852693 /rajeelzahid
Overview
This module introduces a custom hook system for Odoo models, allowing developers to cleanly inject pre/post logic into existing methods, including normal methods, onchange, compute, and more, without overriding via super().
By using @install_hooks, developers can attach logic directly to model functions, making code more modular, maintainable, and less prone to errors caused by traditional super() chains.
Key Features
- Pre/Post Method Hooks: Easily add
_pre_hook_<method>
and_post_hook_<method>
to execute before/after any model method. - Super-less Extension: Eliminate fragile
super()
patterns in favor of isolated, hook-based injections. - Works with Core Method Types: Supports standard methods, computed fields,
onchange
methods, and more. - Minimal Intrusion: Hooks are injected via a clean decorator:
@install_hooks
, keeping code decoupled and readable. - Centralized & Reusable Logic: Enables writing generic reusable behaviors without modifying the base model.
- Ideal for Large-Scale or Modular Odoo Projects: Perfect for teams managing large, layered codebases or building plug-and-play modules.
How to Use
Add @install_hooks decorator in your model class and create new methods with _pre_hook_ and _post_hook_ methods
from odoo import models
# from odoo.tools import install_hooks # will be deprecated in future versions
from odoo.models import install_hooks
@install_hooks
class ResPartner(models.Model):
_inherit = 'res.partner'
def _pre_hook_name_create(self, name):
# do something before calling name_create
...
def _post_hook_name_create(self, name):
# do something after calling name_create
...
Please log in to comment on this module