In Odoo 8.x, you can execute a custom function when data is loaded by using the _inherits attribute in the model's definition and overriding the load() method. This allows you to extend the behavior of the load() method and execute your custom code when records are being loaded into the system.

Here's a step-by-step guide to achieve this:

Step 1: Define your custom model: Assuming you have a custom model called custom.model that inherits from an existing Odoo model, you need to define your custom model with the _inherits attribute.

from openerp import models, fields class CustomModel(models.Model): _name = 'custom.model' _inherits = {'base.model': 'base_model_id'} # Add your custom fields here custom_field = fields.Char() # The field used for inheritance base_model_id = fields.Many2one('base.model', ondelete='cascade')

Step 2: Override the load() method: Now, you can override the load() method in your custom model to execute your custom function when data is loaded.

class CustomModel(models.Model): _inherit = 'custom.model' def load(self, fields_list, data): # Call the parent load() method to perform the regular data loading res = super(CustomModel, self).load(fields_list, data) # Your custom function to execute when data is loaded self.execute_custom_function() return res def execute_custom_function(self): # Your custom function logic goes here # For example, you can perform additional actions after data is loaded pass

By overriding the load() method in your custom model, you can execute your custom function (execute_custom_function()) after the data is loaded into the system.

Remember to replace 'custom.model' with the actual name of your custom model, and 'base.model' with the name of the model from which you are inheriting.

Keep in mind that Odoo 8.x is an outdated version, and it's recommended to upgrade to the latest version (Odoo 14 at the time of writing) for security and feature enhancements.

Have questions or queries?
Get in Touch