Odoo Help


How to hook to events of objects?

Francisco Luz
on 3/28/13, 1:58 AM 3,712 views

I am a drupal developer and am accustomed to the concept of hooks. In a nutshell a hook is a way to jump into the workflow for adding, altering or listening to an event, say for instance "before saving an user" event.

Now lets say for instance that in my custom module I want to grab the invoice data right before it is about to be saved into the database and after all the installed modules have done their bit.

How do I get my module to hook to that particular point in the workflow, what I would call event.

In my use case I would like to get that data and save it somewhere else in real time.

The answer of this question here http://help.openerp.com/question/5677/how-to-trigger-function-on-object-write/ might be what I am looking for, I will try that out.

Francisco Luz
on 3/28/13, 2:34 AM

Fabien Pinckaers (fp)

--Fabien Pinckaers (fp)--
| 6 8 8
fsdsdfsdf, Belgium
--Fabien Pinckaers (fp)--

Odoo Founder & CEO

Fabien Pinckaers (fp)
On 3/28/13, 3:35 PM

I always thought doing hooks is a bit "old school" development practice :)

In order to hook your code on an existing object, you never have to define hooks or connect to existing hooks. We use standard inheritances practices between objects.

Suppose you have an object like this:

class sale_order(osv.osv):
  def my_method(self, **args):
     # This method do something
     return True

If you want to hook to the my_method, you create an object that inherits from the sale.order object and extend it.

class sale_order(osv.osv):
  _inherit = 'sale.order'
  def my_method(self, **args):
     # do something before
     value = super(sale_order, self).my_method(self, **args)
     # do something after
     return value

And how can you redefine a method of a class like mail.thread?

Carlos Almeida
on 1/19/16, 8:41 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/28/13, 1:58 AM
Seen: 3712 times
Last updated: 3/16/15, 8:10 AM