v 16.0 Third Party 10
Odoo Online
On Premise
Community Apps Dependencies
Lines of code 3036
Technical Name generic_system_event
Versions 13.0 12.0 16.0 15.0 14.0
You bought this module and need support? Click here!
Odoo Online
On Premise
Community Apps Dependencies
Lines of code 3036
Technical Name generic_system_event
Versions 13.0 12.0 16.0 15.0 14.0

Generic System Event

License: OPL-1 CR&D

This module provides framework that allows to make odoo event-driven. Note, that in this case event means business event.

With this module, you can easily convert your model to event source, and then handle events from that model in any other place of odoo. With this module you may forget about again and again overriding ``write`` methods.

Why this is needed?

This module allows to step away from infinite overrides of write/create, or overriding other methods to add some logic. Instead, with this framework, you can think in event driven way: just trigger event with all needed data where it is needed. And handle this event in multiple places in multiple modules, in multiple related models.

For example, you can define event like Invoice Paid, and then handle it on Sale Order, In CRM, or in any other related object. The framework, will automatically call all registered handlers of this event. This way, it is possible to significantly simplify complex logic of handling events.

Also, because events are stored in database, you always have history of events related to specific record, which could help in debug, or in tracking what is going on in some cases.

How to use

  1. Create model for events

    At first, you have to create model to store events produced by your event source.

    You can define such model as following:

                            class MyEvent(models.Model):
                                _name = 'my.event'
                                _inherit = 'generic.system.event.data.mixin'
                                # You can add here fields specific to your events.
                                # For example:
                                my_param_old = fields.Char()
                                my_param_new = fields.Char()
  2. Create event source

    You have to inherit your model from ``generic.system.event.source.mixin`` to to make it event source, capable to generate events. For example, let's define simple model with one field ``param``, and trigger event any type this field changed.

                        from odoo.addons.generic_mixin import post_write
                        from odoo.addons.generic_system_event import on_event
                        class MyEventSource(models.Model):
                             _name = 'my.event.source'
                             _inherit = 'generic.system.event.source.mixin'
                             # This is needed to automatically register event source
                             # Other wise, you will need additionally to define
                             # event source in XML.
                             # Automatic event source will be generated with
                             # xmlid: your_module_name.system_event_source__my_event_source
                             _generic_system_event_source__auto_create = True
                             # name of data model for events from this event source
                             _generic_system_event_source__event_data_model = 'my.event'
                             # Next, we can define some data on this model
                             my_param = fields.Char()
                             # This field will be changed automatically by event handler.
                             counter = Integer
                             # Let's trigger event
                             def _after_my_param_changed_trigger_event(self, changes):
                                 # The line below triggers event
                                 self.trigger_event('my-param-changed', {
                                     'my_param_old': changes['my_param'].old_val,
                                     'my_param_new': changes['my_param'].new_val,
                             # Next, we can define event handler:
                             def _on_my_param_changed(self, event):
                                 self.counter += 1
  3. Define event types

    Next, we have to define all event types in the XML.

                            My Events
                            My Param Changed
  4. Define views for events

    Next we have to define views for event data model (that model that is used to store events).

  5. Add stat-button to show events on your view

    If needed, you can add stat-button on your form view of 'my.event.source' to show related events. All you need is to add following xml snippet.


Note, that method ``action_show_related_system_events`` already implemented in ``generic.system.event.source.mixin``, thus, this xml-snipped is all you need.

Advanced usage

For advanced usage, look for documentation in the code. Basically, this framework, allows you to handle events triggered in context of one model (for example invoices), in context of another related model (for example sale order).

All you need for this, is to specify mapping in XML (see ``generic.system.event.source.handler.map`` model for more info). Also, in this case, you have to apply ``generic.system.event.handler.mixin`` to handler model to allow framework to automatically discover handlers.

Launch your own ITSM system in 60 seconds:

Create your own Bureaucrat ITSM database yodoo.systems


Website Contact us Bug Requests

This module is maintained by the Center of Research & Development company.

We can provide you further Odoo Support, Odoo implementation, Odoo customization, Odoo 3rd Party development and integration software, consulting services. Our main goal is to provide the best quality product for you.

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 or have a question related to your purchase, please use the support page.