Skip to Content
Menu

Hook Model Methods

by
Odoo
v 18.0 Third Party 16
Download for v 18.0 Deploy on Odoo.sh
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 78
Technical Name hook_model_methods
LicenseLGPL-3
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 78
Technical Name hook_model_methods
LicenseLGPL-3

Hook Model Methods

1

📢 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
        ...

Developer note

This module is more of my personal development and to show the creativity.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.